]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Mantis issue 0021079: problems with Explode.
authorjfa <jfa@opencascade.com>
Fri, 4 Feb 2011 14:50:33 +0000 (14:50 +0000)
committerjfa <jfa@opencascade.com>
Fri, 4 Feb 2011 14:50:33 +0000 (14:50 +0000)
idl/GEOM_Gen.idl
src/EntityGUI/EntityGUI_SubShapeDlg.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.hxx
src/GEOM_I/GEOM_IShapesOperations_i.cc
src/GEOM_I/GEOM_IShapesOperations_i.hh
src/GEOM_SWIG/geompyDC.py

index 1da35ccd4c117b45b9d08d7da6bce371cc3f5c10..142b0585c7ad64119095dd2aa982bcdcb6f4516d 100644 (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.
      */
index 4fff521458c9c784419ae7baf0b6c1e61a82fe4e..9122a7d74b97453202841afdcdac064a5a616779 100644 (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;
index e916f423202d39dd4fb1c055c29e6a85cd6a8919..0eb0d4ac2771a67b5bd2da4292e8c070359b67f5 100644 (file)
 //
 //  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>
 
@@ -267,7 +266,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeEdgeWire
     if ( theLinearTolerance == DEF_LIN_TOL )
       GEOM::TPythonDump(aFunction) << anEdge  << " = geompy.MakeEdgeWire("
                                    << theWire << ")";
-    else 
+    else
       GEOM::TPythonDump(aFunction) << anEdge  << " = geompy.MakeEdgeWire("
                                    << theWire << ", " << theLinearTolerance << ")";
   }
@@ -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;
index 8f3132a932eb8871586af0f1ea78276e7feaea9d..607a1283f6f2eb925663fb3bda6de613682bb0f3 100644 (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);
@@ -88,18 +87,24 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
   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);
index fcf400be55979bd0c729fc07656976e4554d0bb6..b6eb40db60e123b40023d59dd5515817abbd0a04 100644 (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();
index 424228f981edc4926ca99662000c8230c3819441..9cc86a98968be71a2bedbd6106af5f7fcf99ecc8 100644 (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,
index ef71fbb8cfd3e6400c2737ef7a2ba9690943fa86..bb7efcfe1b6c5690853e2e40c0bbf9401b7049cd 100644 (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
         ## @}
 
@@ -2259,21 +2269,6 @@ class geompyDC(GEOM._objref_GEOM_Gen):
                 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
         ## @}