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
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.
*/
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;
//
// 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>
if ( theLinearTolerance == DEF_LIN_TOL )
GEOM::TPythonDump(aFunction) << anEdge << " = geompy.MakeEdgeWire("
<< theWire << ")";
- else
+ else
GEOM::TPythonDump(aFunction) << anEdge << " = geompy.MakeEdgeWire("
<< theWire << ", " << theLinearTolerance << ")";
}
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
- const Standard_Boolean isOldSorting)
+ const ExplodeType theExplodeType)
{
SetErrorCode(KO);
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())) {
}
}
}
- 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())
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);
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;
(Handle(GEOM_Object) theShape,
const Standard_Integer theShapeType,
const Standard_Boolean isSorted,
- const Standard_Boolean isOldSorting)
+ const ExplodeType theExplodeType)
{
SetErrorCode(KO);
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())) {
}
}
}
- } 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())
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);
//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;
// Created :
// Author : modified by Lioka RAZAFINDRAZAKA (CEA) 22/06/2007
// Project : SALOME
-// $Header$
//=============================================================================
#ifndef _GEOMImpl_IShapesOperations_HXX_
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);
Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetExistingSubObjects
(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);
//=============================================================================
/*!
- * MakeExplode
+ * MakeExplode (including theShape itself, bad sorting)
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeExplode (GEOM::GEOM_Object_ptr theShape,
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();
//=============================================================================
/*!
- * MakeAllSubShapes
+ * MakeAllSubShapes (including theShape itself, good sorting)
*/
//=============================================================================
GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeAllSubShapes (GEOM::GEOM_Object_ptr theShape,
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();
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();
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();
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,
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.
## 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.
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
## @}
ListOfIDs.append(AllShapeIDsList[ind - 1])
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
## @}