Mantis issue 0021079: problems with Explode.

This commit is contained in:
jfa 2011-02-04 14:50:33 +00:00
parent 2a4038f828
commit ca0d85f801
7 changed files with 134 additions and 56 deletions

View File

@ -1478,7 +1478,8 @@ module GEOM
in boolean isSorted);
/*!
* Explode a shape on subshapes of a given type.
* Explode a shape on subshapes of a given type. If the
* shape itself has the given type, it is also returned.
* \param theShape Shape to be exploded.
* \param theShapeType Type of sub-shapes to be retrieved.
* \param isSorted If this parameter is TRUE, sub-shapes will be
@ -1489,6 +1490,19 @@ module GEOM
in long theShapeType,
in boolean isSorted);
/*!
* Extract all subshapes of the given type from
* the given shape, excluding the shape itself.
* \param theShape Shape to be exploded.
* \param theShapeType Type of sub-shapes to be retrieved.
* \param isSorted If this parameter is TRUE, sub-shapes will be
* sorted by coordinates of their gravity centers.
* \return List of sub-shapes of type theShapeType, contained in theShape.
*/
ListOfGO ExtractSubShapes (in GEOM_Object theShape,
in long theShapeType,
in boolean isSorted);
/*!
* Deprecated method. Use GetAllSubShapesIDs() instead.
*/

View File

@ -555,7 +555,7 @@ bool EntityGUI_SubShapeDlg::isValid (QString& msg)
bool EntityGUI_SubShapeDlg::execute (ObjectList& objects)
{
GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
GEOM::ListOfGO_var aList = anOper->MakeAllSubShapes(myObject, shapeType(), true);
GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true);
if (!aList->length())
return false;

View File

@ -19,11 +19,10 @@
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : GEOMImpl_IShapesOperations.cxx
// Created :
// Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
// Project : SALOME
// $Header$
// File : GEOMImpl_IShapesOperations.cxx
// Created :
// Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
// Project : SALOME
#include <Standard_Stream.hxx>
@ -893,7 +892,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
const Standard_Boolean isOldSorting)
const ExplodeType theExplodeType)
{
SetErrorCode(KO);
@ -911,7 +910,8 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
if (aShape.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND))
{
TopoDS_Iterator It (aShape, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
if (mapShape.Add(It.Value())) {
@ -922,7 +922,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
}
}
}
else if ( aShape.ShapeType() != theShapeType ) // issue 0021079, prevent from returning aShape
else if (theExplodeType != EXPLODE_NEW_EXCLUDE_MAIN || aShape.ShapeType() != theShapeType) // issue 0021079
{
TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
for (; exp.More(); exp.Next())
@ -936,8 +936,12 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
return aSeq;
}
if (isSorted)
if (isSorted) {
bool isOldSorting = false;
if (theExplodeType == EXPLODE_OLD_INCLUDE_MAIN)
isOldSorting = true;
SortShapes(listShape, isOldSorting);
}
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aShape, anIndices);
@ -982,13 +986,22 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeExplode
anAsciiList.Trunc(anAsciiList.Length() - 1);
GEOM::TPythonDump pd (aMainShape, /*append=*/true);
pd << "[" << anAsciiList.ToCString();
if (isSorted)
pd << "] = geompy.SubShapeAllSorted" << (isOldSorting ? "(" : "Centres(");
else
pd << "] = geompy.SubShapeAll(";
pd << theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
pd << "[" << anAsciiList.ToCString() << "] = geompy.";
switch (theExplodeType) {
case EXPLODE_NEW_EXCLUDE_MAIN:
pd << "ExtractShapes(" << theShape << ", "
<< TopAbs_ShapeEnum(theShapeType) << ", " << (isSorted ? "TRUE" : "FALSE") << ")";
break;
case EXPLODE_NEW_INCLUDE_MAIN:
pd << "SubShapeAll" << (isSorted ? "SortedCentres(" : "(")
<< theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
break;
case EXPLODE_OLD_INCLUDE_MAIN:
pd << "SubShapeAll" << (isSorted ? "Sorted(" : "(")
<< theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
break;
default: ;
}
SetErrorCode(OK);
return aSeq;
@ -1003,7 +1016,7 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
const Standard_Boolean isOldSorting)
const ExplodeType theExplodeType)
{
SetErrorCode(KO);
@ -1018,7 +1031,8 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
if (aShape.ShapeType() == TopAbs_COMPOUND &&
(TopAbs_ShapeEnum(theShapeType) == TopAbs_SHAPE ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPSOLID ||
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND)) {
TopAbs_ShapeEnum(theShapeType) == TopAbs_COMPOUND))
{
TopoDS_Iterator It (aShape, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
if (mapShape.Add(It.Value())) {
@ -1028,7 +1042,8 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
}
}
}
} else if ( aShape.ShapeType() != theShapeType ) // issue 0021079, prevent from returning aShape
}
else if (theExplodeType != EXPLODE_NEW_EXCLUDE_MAIN || aShape.ShapeType() != theShapeType) // issue 0021079
{
TopExp_Explorer exp (aShape, TopAbs_ShapeEnum(theShapeType));
for (; exp.More(); exp.Next())
@ -1042,8 +1057,12 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
return aSeq;
}
if (isSorted)
if (isSorted) {
bool isOldSorting = false;
if (theExplodeType == EXPLODE_OLD_INCLUDE_MAIN)
isOldSorting = true;
SortShapes(listShape, isOldSorting);
}
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aShape, anIndices);
@ -1060,11 +1079,19 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::SubShapeAllIDs
//Make a Python command
GEOM::TPythonDump pd (aFunction, /*append=*/true);
pd << "listSubShapeIDs = geompy.SubShapeAll";
if (isSorted)
pd << "Sorted" << (isOldSorting ? "IDs(" : "CentresIDs(");
else
pd << "IDs(";
pd << theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
switch (theExplodeType) {
case EXPLODE_NEW_EXCLUDE_MAIN:
break;
case EXPLODE_NEW_INCLUDE_MAIN:
pd << (isSorted ? "SortedCentresIDs(" : "IDs(")
<< theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
break;
case EXPLODE_OLD_INCLUDE_MAIN:
pd << (isSorted ? "SortedIDs(" : "IDs(")
<< theShape << ", " << TopAbs_ShapeEnum(theShapeType) << ")";
break;
default: ;
}
SetErrorCode(OK);
return aSeq;

View File

@ -24,7 +24,6 @@
// Created :
// Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
// Project : SALOME
// $Header$
//=============================================================================
#ifndef _GEOMImpl_IShapesOperations_HXX_
@ -54,10 +53,10 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
Standard_EXPORT ~GEOMImpl_IShapesOperations();
Standard_EXPORT Handle(GEOM_Object) MakeEdge (Handle(GEOM_Object) thePoint1,
Handle(GEOM_Object) thePoint2);
Handle(GEOM_Object) thePoint2);
Standard_EXPORT Handle(GEOM_Object) MakeEdgeWire (Handle(GEOM_Object) theWire,
const Standard_Real theLinearTolerance,
const Standard_Real theAngularTolerance);
const Standard_Real theLinearTolerance,
const Standard_Real theAngularTolerance);
Standard_EXPORT Handle(GEOM_Object) MakeWire (std::list<Handle(GEOM_Object)> theEdgesAndWires,
const Standard_Real theTolerance);
@ -89,17 +88,23 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
(Handle(GEOM_Object) theShape,
const Standard_Boolean theGroupsOnly);
enum ExplodeType {
EXPLODE_OLD_INCLUDE_MAIN,
EXPLODE_NEW_INCLUDE_MAIN,
EXPLODE_NEW_EXCLUDE_MAIN
};
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) MakeExplode
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
const Standard_Boolean isOldSorting = Standard_False);
const ExplodeType theExplodeType = EXPLODE_NEW_INCLUDE_MAIN);
Standard_EXPORT Handle(TColStd_HSequenceOfInteger) SubShapeAllIDs
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
const Standard_Boolean isOldSorting = Standard_False);
const ExplodeType theExplodeType = EXPLODE_NEW_INCLUDE_MAIN);
Standard_EXPORT Handle(GEOM_Object) GetSubShape (Handle(GEOM_Object) theMainShape,
const Standard_Integer theID);

View File

@ -469,7 +469,7 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetExistingSubObjects (GEOM::GEOM_Obje
//=============================================================================
/*!
* MakeExplode
* MakeExplode (including theShape itself, bad sorting)
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
@ -482,7 +482,8 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr the
if (aShape.IsNull()) return aSeq._retn();
Handle(TColStd_HSequenceOfTransient) aHSeq =
GetOperations()->MakeExplode(aShape, theShapeType, isSorted, Standard_True);
GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
GEOMImpl_IShapesOperations::EXPLODE_OLD_INCLUDE_MAIN);
if (!GetOperations()->IsDone() || aHSeq.IsNull())
return aSeq._retn();
@ -496,7 +497,7 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr the
//=============================================================================
/*!
* MakeAllSubShapes
* MakeAllSubShapes (including theShape itself, good sorting)
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeAllSubShapes (GEOM::GEOM_Object_ptr theShape,
@ -509,7 +510,37 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeAllSubShapes (GEOM::GEOM_Object_pt
if (aShape.IsNull()) return aSeq._retn();
Handle(TColStd_HSequenceOfTransient) aHSeq =
GetOperations()->MakeExplode(aShape, theShapeType, isSorted, Standard_False);
GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
GEOMImpl_IShapesOperations::EXPLODE_NEW_INCLUDE_MAIN);
if (!GetOperations()->IsDone() || aHSeq.IsNull())
return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();
aSeq->length(aLength);
for (Standard_Integer i = 1; i <= aLength; i++)
aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
return aSeq._retn();
}
//=============================================================================
/*!
* ExtractSubShapes (excluding theShape itself, good sorting)
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::ExtractSubShapes (GEOM::GEOM_Object_ptr theShape,
const CORBA::Long theShapeType,
const CORBA::Boolean isSorted)
{
GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
if (aShape.IsNull()) return aSeq._retn();
Handle(TColStd_HSequenceOfTransient) aHSeq =
// TODO: enum instead of bool for the last argument
GetOperations()->MakeExplode(aShape, theShapeType, isSorted,
GEOMImpl_IShapesOperations::EXPLODE_NEW_EXCLUDE_MAIN);
if (!GetOperations()->IsDone() || aHSeq.IsNull())
return aSeq._retn();
@ -536,7 +567,8 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::SubShapeAllIDs (GEOM::GEOM_Object_pt
if (aShape.IsNull()) return aSeq._retn();
Handle(TColStd_HSequenceOfInteger) aHSeq =
GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted, Standard_True);
GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted,
GEOMImpl_IShapesOperations::EXPLODE_OLD_INCLUDE_MAIN);
if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();
@ -562,7 +594,8 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetAllSubShapesIDs (GEOM::GEOM_Objec
if (aShape.IsNull()) return aSeq._retn();
Handle(TColStd_HSequenceOfInteger) aHSeq =
GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted, Standard_False);
GetOperations()->SubShapeAllIDs(aShape, theShapeType, isSorted,
GEOMImpl_IShapesOperations::EXPLODE_NEW_INCLUDE_MAIN);
if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();

View File

@ -90,6 +90,10 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i :
CORBA::Long theShapeType,
CORBA::Boolean isSorted);
GEOM::ListOfGO* ExtractSubShapes (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,
CORBA::Boolean isSorted);
// Deprecated, use GetAllSubShapesIDs() instead
GEOM::ListOfLong* SubShapeAllIDs (GEOM::GEOM_Object_ptr theShape,
CORBA::Long theShapeType,

View File

@ -2152,6 +2152,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
return ListObj
## Explode a shape on subshapes of a given type.
# If the shape itself matches the type, it is also returned.
# @param aShape Shape to be exploded.
# @param aType Type of sub-shapes to be retrieved.
# @return List of sub-shapes of type theShapeType, contained in theShape.
@ -2190,6 +2191,7 @@ class geompyDC(GEOM._objref_GEOM_Gen):
## Explode a shape on subshapes of a given type.
# Sub-shapes will be sorted by coordinates of their gravity centers.
# If the shape itself matches the type, it is also returned.
# @param aShape Shape to be exploded.
# @param aType Type of sub-shapes to be retrieved.
# @return List of sub-shapes of type theShapeType, contained in theShape.
@ -2227,6 +2229,14 @@ class geompyDC(GEOM._objref_GEOM_Gen):
anObj = self.GetSubShape(aShape, ListOfIDs)
return anObj
## Extract shapes (excluding the main shape) of given type
# @param aShape shape
# @param aType shape type
def ExtractShapes(self, aShape, aType, isSorted = False):
ListObj = self.ShapesOp.ExtractSubShapes(aShape, aType, isSorted)
RaiseIfFailed("ExtractSubShapes", self.ShapesOp)
return ListObj
# end of l4_decompose
## @}
@ -2260,21 +2270,6 @@ class geompyDC(GEOM._objref_GEOM_Gen):
anObj = self.GetSubShape(aShape, ListOfIDs)
return anObj
## Extract shapes (main shape or sub-shape) of given type
# @param aShape shape
# @param aType shape type
def ExtractShapes(self, aShape, aType, sorted = False):
ret = []
t = EnumToLong(aShape.GetShapeType())
aType = EnumToLong(aType)
if t == aType:
ret.append(aShape )
elif sorted:
ret = self.SubShapeAllSortedCentres(aShape, aType)
else:
ret = self.SubShapeAll(aShape, aType)
return ret
# end of l4_decompose_d
## @}