From 3892ca7188dab03fa8383063b0df38148d23fe6a Mon Sep 17 00:00:00 2001 From: rnc Date: Wed, 23 Jan 2013 16:31:10 +0000 Subject: [PATCH] added a function to retrieve a list of IDs from a list of subshapes. This function is provided for better performance when searching the IDs of a great number of subshapes. --- idl/GEOM_Gen.idl | 8 +++ src/GEOMImpl/GEOMImpl_IShapesOperations.cxx | 54 +++++++++++++++++++-- src/GEOMImpl/GEOMImpl_IShapesOperations.hxx | 3 ++ src/GEOM_I/GEOM_IShapesOperations_i.cc | 43 ++++++++++++++++ src/GEOM_I/GEOM_IShapesOperations_i.hh | 3 ++ src/GEOM_SWIG/geompyDC.py | 26 ++++++++++ 6 files changed, 134 insertions(+), 3 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index af98eeb8a..b7bcf45e2 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -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. * diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 41de518cb..fd1771a6a 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -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 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::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 diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index 4c42a73d7..745142c8c 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -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 theSubShapes); Standard_EXPORT Standard_Integer GetTopologyIndex (Handle(GEOM_Object) theMainShape, Handle(GEOM_Object) theSubShape); diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index cee18553c..cd3aac8aa 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -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 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 inside + 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 diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index c01b6317e..41def03a9 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -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); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 0dc6009ef..bfc8c533c 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -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 aSubShapes inside aShape + # 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 ## @} -- 2.39.2