]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
added a function to retrieve a list of IDs from a list of subshapes. This function...
authorrnc <rnc@opencascade.com>
Wed, 23 Jan 2013 16:31:10 +0000 (16:31 +0000)
committerrnc <rnc@opencascade.com>
Wed, 23 Jan 2013 16:31:10 +0000 (16:31 +0000)
idl/GEOM_Gen.idl
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 af98eeb8a8eec1f5e3b889ad60426f20467d9f1a..b7bcf45e20c1234da2a8a9ffadda47540e92c1a9 100644 (file)
@@ -1841,6 +1841,14 @@ module GEOM
      */
     long GetSubShapeIndex (in GEOM_Object theMainShape, in GEOM_Object theSubShape);
 
+    /*!
+     *  Get global indices of \a theSubShapes in \a theMainShape.
+     *  \param theMainShape Main shape.
+     *  \param theSubShapes List of sub-shapes of the main shape.
+     *  \return list of global indices of \a theSubShapes in \a theMainShape.
+     */
+    ListOfLong GetSubShapesIndices (in GEOM_Object theMainShape, in ListOfGO theSubShapes);
+
     /*!
      *  \brief Get index of \a theSubShape in \a theMainShape, unique among sub-shapes of the same type.
      *
index 41de518cb0f250ba4d5c09ba155e31713ab28199..fd1771a6a45b5d6ceca473b5bb1056c16ce86a22 100644 (file)
@@ -1558,14 +1558,62 @@ Standard_Integer GEOMImpl_IShapesOperations::GetSubShapeIndex (Handle(GEOM_Objec
 
   TopTools_IndexedMapOfShape anIndices;
   TopExp::MapShapes(aMainShape, anIndices);
-  if (anIndices.Contains(aSubShape)) {
+//   if (anIndices.Contains(aSubShape)) {
+//     SetErrorCode(OK);
+//     return anIndices.FindIndex(aSubShape);
+//   }
+  int id = anIndices.FindIndex(aSubShape);
+  if (id > 0)
+  {
     SetErrorCode(OK);
-    return anIndices.FindIndex(aSubShape);
+    return id;
   }
-
   return -1;
 }
 
+
+
+//=============================================================================
+/*!
+ *  GetSubShapeIndices
+ */
+//=============================================================================
+Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetSubShapesIndices (Handle(GEOM_Object) theMainShape,
+                                                                                    std::list<Handle(GEOM_Object)> theSubShapes)
+{
+  MESSAGE("GEOMImpl_IShapesOperations::GetSubShapesIndices")
+  SetErrorCode(KO);
+  
+  Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
+  
+  TopoDS_Shape aMainShape = theMainShape->GetValue();
+  if (aMainShape.IsNull())
+  {
+    MESSAGE("NULL main shape")
+    return NULL;
+  }
+  
+  TopTools_IndexedMapOfShape anIndices;
+  TopExp::MapShapes(aMainShape, anIndices);
+  
+  std::list<Handle(GEOM_Object)>::iterator it;
+  for (it=theSubShapes.begin(); it != theSubShapes.end(); ++it)
+  {
+    TopoDS_Shape aSubShape = (*it)->GetValue(); 
+    if (aSubShape.IsNull())
+    {
+      MESSAGE("NULL subshape")
+      return NULL;
+    }
+    int id = anIndices.FindIndex(aSubShape);
+    aSeq->Append(id);
+  }  
+  
+  SetErrorCode(OK);
+  return aSeq;
+}
+
+
 //=============================================================================
 /*!
  *  GetTopologyIndex
index 4c42a73d75b818881c81b480c26b2f1630b8aa56..745142c8c584a9af142f10f591053d01a52cd0be 100644 (file)
@@ -137,6 +137,9 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
 
   Standard_EXPORT Standard_Integer GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
                                                      Handle(GEOM_Object) theSubShape);
+  
+  Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetSubShapesIndices (Handle(GEOM_Object) theMainShape,
+                                                                          std::list<Handle(GEOM_Object)> theSubShapes);
 
   Standard_EXPORT Standard_Integer GetTopologyIndex (Handle(GEOM_Object) theMainShape,
                                                      Handle(GEOM_Object) theSubShape);
index cee18553c219adff6e803018108942e7c1232153..cd3aac8aad1b767e866430423c0ea889b591eb7c 100644 (file)
@@ -831,6 +831,49 @@ CORBA::Long GEOM_IShapesOperations_i::GetSubShapeIndex
   return anID;
 }
 
+//=============================================================================
+/*!
+ *  GetSubShapesIndices
+ */
+//=============================================================================
+GEOM::ListOfLong* GEOM_IShapesOperations_i::GetSubShapesIndices
+  (GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfGO& theSubShapes)
+{
+  GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
+  
+  //Get the reference main shape
+  Handle(GEOM_Object) aMainShapeRef = GetObjectImpl(theMainShape); 
+  if (aMainShapeRef.IsNull()) return aSeq._retn();
+      
+  //Get the subshapes
+  std::list<Handle(GEOM_Object)> aShapes;
+  int aLen = theSubShapes.length();
+  for (int ind = 0; ind < aLen; ind++) {
+    Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
+    if (aSh.IsNull())
+    {
+      MESSAGE("NULL shape")
+      return aSeq._retn();
+    }
+    aShapes.push_back(aSh);
+  }
+
+  //Get the IDs of <theSubShapes> inside <theMainShape>
+  Handle(TColStd_HSequenceOfInteger) aHSeq = 
+  GetOperations()->GetSubShapesIndices(aMainShapeRef, aShapes);
+  
+  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] = aHSeq->Value(i);
+
+  return aSeq._retn();
+}
+
+
 //=============================================================================
 /*!
  *  GetTopologyIndex
index c01b6317e7b4c2a891c4375c3e78262d9f42c3ce..41def03a9bdd5a8286af451d6ceff864d856b3fa 100644 (file)
@@ -128,6 +128,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i :
 
   CORBA::Long GetSubShapeIndex (GEOM::GEOM_Object_ptr theMainShape,
                                 GEOM::GEOM_Object_ptr theSubShape);
+  
+  GEOM::ListOfLong* GetSubShapesIndices (GEOM::GEOM_Object_ptr theMainShape,
+                                         const GEOM::ListOfGO& theSubShapes);
 
   CORBA::Long GetTopologyIndex (GEOM::GEOM_Object_ptr theMainShape,
                                 GEOM::GEOM_Object_ptr theSubShape);
index 0dc6009ef869666f5f77b4bedb6f75d615134427..bfc8c533cf842ef83a9245af754c9fcc24b9b0d3 100644 (file)
@@ -5194,6 +5194,32 @@ class geompyDC(GEOM._objref_GEOM_Gen):
             anID = self.LocalOp.GetSubShapeIndex(aShape, aSubShape)
             RaiseIfFailed("GetSubShapeIndex", self.LocalOp)
             return anID
+            
+        ## Obtain unique IDs of sub-shapes <VAR>aSubShapes</VAR> inside <VAR>aShape</VAR>
+        #  This function is provided for performance purpose. The complexity is O(n) with n
+        #  the number of subobjects of aShape
+        #  @param aShape Shape to get sub-shape of.
+        #  @param aSubShapes Sub-shapes of aShape.
+        #  @return list of IDs of found sub-shapes.
+        #
+        #  @ref swig_all_decompose "Example"
+        def GetSubShapesIDs(self, aShape, aSubShapes):
+            """
+            Obtain a list of IDs of sub-shapes aSubShapes inside aShape
+            This function is provided for performance purpose. The complexity is O(n) with n
+            the number of subobjects of aShape
+
+            Parameters:
+               aShape Shape to get sub-shape of.
+               aSubShapes Sub-shapes of aShape.
+
+            Returns:
+               List of IDs of found sub-shape.
+            """
+            # Example: see GEOM_TestAll.py
+            anIDs = self.ShapesOp.GetSubShapesIndices(aShape, aSubShapes)
+            RaiseIfFailed("GetSubShapesIndices", self.ShapesOp)
+            return anIDs
 
         # end of l4_access
         ## @}