]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Fix for the "0021561: EDF 2184 GEOM: Group with second shape restriction" issue.
authorrnv <rnv@opencascade.com>
Wed, 16 May 2012 14:34:00 +0000 (14:34 +0000)
committerrnv <rnv@opencascade.com>
Wed, 16 May 2012 14:34:00 +0000 (14:34 +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
src/GroupGUI/GroupGUI_GroupDlg.cxx

index 905b1b6c798546ec3f4023863b6dc58835ff6872..78339217004e03cb7a7828c04157d9d2dc810e57 100644 (file)
@@ -2118,6 +2118,17 @@ module GEOM
      */
     GEOM_Object GetSame (in GEOM_Object theShapeWhere,
                                 in GEOM_Object theShapeWhat);
+
+    /*!
+     *  \brief Get sub-shape Ids of theShapeWhere, which are
+     *   coincident with \a theShapeWhat that can either SOLID, FACE, EDGE or VERTEX.
+     *  \param theShapeWhere Shape to find sub-shapes of.
+     *  \param theShapeWhat Shape, specifying what to find.
+     *  \return found sub-shape Ids.
+     */
+    ListOfLong GetSameIDs (in GEOM_Object theShapeWhere,
+                           in GEOM_Object theShapeWhat);
+
   };
 
  // # GEOM_IBlocksOperations: 
index 8577ac995a8aa058c1fec557dea92268abbb6fb1..b81b261ce0e0a7c62376ca50427225407460d986 100644 (file)
@@ -4914,3 +4914,109 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSame(const Handle(GEOM_Object
 
   return aResult;
 }
+
+
+//=======================================================================
+//function : GetSameIDs
+//purpose  :
+//=======================================================================
+Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetSameIDs(const Handle(GEOM_Object)& theShapeWhere,
+                                                        const Handle(GEOM_Object)& theShapeWhat)
+{
+  SetErrorCode(KO);
+  if (theShapeWhere.IsNull() || theShapeWhat.IsNull()) return NULL;
+
+  TopoDS_Shape aWhere = theShapeWhere->GetValue();
+  TopoDS_Shape aWhat  = theShapeWhat->GetValue();
+
+  if (aWhere.IsNull() || aWhat.IsNull()) return NULL;
+
+  int anIndex = -1;
+  bool isFound = false;
+  TopTools_ListOfShape listShape;
+  TopTools_MapOfShape aMap;
+
+  if (aWhat.ShapeType() == TopAbs_COMPOUND || aWhat.ShapeType() == TopAbs_COMPSOLID) {
+    TopoDS_Iterator It (aWhat, Standard_True, Standard_True);
+    if (It.More()) aWhat = It.Value();
+    It.Next();
+    if (It.More()) {
+      SetErrorCode("Compounds of two or more shapes are not allowed for aWhat argument");
+      return NULL;
+    }
+  }
+
+  switch (aWhat.ShapeType()) {
+    case TopAbs_VERTEX: {
+      gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(aWhat));
+      TopExp_Explorer E(aWhere, TopAbs_VERTEX);
+      for(; E.More(); E.Next()) {
+        if(!aMap.Add(E.Current())) continue;
+        gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(E.Current()));
+        if(P.Distance(P2) <= MAX_TOLERANCE) {
+          listShape.Append(E.Current());
+        }
+      }
+      break;
+                        }
+    case TopAbs_EDGE: {
+      TopoDS_Edge anEdge = TopoDS::Edge(aWhat);
+      TopExp_Explorer E(aWhere, TopAbs_EDGE);
+      for(; E.More(); E.Next()) {
+        if(!aMap.Add(E.Current())) continue;
+        if(isSameEdge(anEdge, TopoDS::Edge(E.Current()))) {
+          listShape.Append(E.Current());
+        }
+      }
+      break;
+                      }
+    case TopAbs_FACE: {
+      TopoDS_Face aFace = TopoDS::Face(aWhat);
+      TopExp_Explorer E(aWhere, TopAbs_FACE);
+      for(; E.More(); E.Next()) {
+        if(!aMap.Add(E.Current())) continue;
+        if(isSameFace(aFace, TopoDS::Face(E.Current()))) {
+          listShape.Append(E.Current());
+        }
+      }
+      break;
+                      }
+    case TopAbs_SOLID: {
+      TopoDS_Solid aSolid = TopoDS::Solid(aWhat);
+      TopExp_Explorer E(aWhere, TopAbs_SOLID);
+      for(; E.More(); E.Next()) {
+        if(!aMap.Add(E.Current())) continue;
+        if(isSameSolid(aSolid, TopoDS::Solid(E.Current()))) {
+          listShape.Append(E.Current());
+        }
+      }
+      break;
+                       }
+    default:
+      return NULL;
+  }
+
+  if ( !listShape.IsEmpty() ) {
+    TopTools_IndexedMapOfShape anIndices;
+    TopExp::MapShapes(aWhere, anIndices);
+    TopTools_ListIteratorOfListOfShape itSub (listShape);
+    Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
+    for (; itSub.More(); itSub.Next()) {
+      if (anIndices.Contains(itSub.Value()))
+        aSeq->Append(anIndices.FindIndex(itSub.Value()));
+    }
+    SetErrorCode(OK);
+    // The GetSameIDs() doesn't change object so no new function is required.
+    Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShapeWhere,theShapeWhat)->GetLastFunction();
+
+  // Make a Python command
+  GEOM::TPythonDump(aFunction)
+    << "listSameIDs = geompy.GetSameIDs("
+    << theShapeWhere << ", "
+    << theShapeWhat << ")";
+    return aSeq;
+  } else {
+    SetErrorCode(NOT_FOUND_ANY);
+    return NULL; 
+  }
+}
index 93971ff83d37476a557f05c62ee519b29d4c1ed2..21885888ac180daa1b19135c0b883236b7bdfa1a 100644 (file)
@@ -305,6 +305,15 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
   Standard_EXPORT Handle(GEOM_Object) GetSame(const Handle(GEOM_Object)& theShapeWhere,
                                               const Handle(GEOM_Object)& theShapeWhat);
 
+  /*!
+   * \brief Searches a shape equal to theWhat in the context of theWhere
+   * \param theShapeWhere - a context shap
+   * \param theShapeWhat - a sample shape
+   * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
+   */
+  Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetSameIDs(const Handle(GEOM_Object)& theShapeWhere,
+                                                                 const Handle(GEOM_Object)& theShapeWhat);
+
   /*!
    * \brief Find IDs of sub-shapes complying with given status about surface
     * \param theBox - the box to check state of sub-shapes against
index ca40dbf23100f82177b719170b038b06c2a48f27..cee18553c219adff6e803018108942e7c1232153 100644 (file)
@@ -1832,3 +1832,34 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSame
 
   return GetObject(anObject);
 }
+
+//=============================================================================
+/*!
+ *  GetSameIDs
+ */
+//=============================================================================
+GEOM::ListOfLong* GEOM_IShapesOperations_i::GetSameIDs
+                                          (GEOM::GEOM_Object_ptr theShapeWhere,
+                                           GEOM::GEOM_Object_ptr theShapeWhat) {
+  GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
+
+  //Get the reference objects
+  Handle(GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere);
+  Handle(GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat);
+
+  if (aShapeWhere.IsNull() ||
+      aShapeWhat.IsNull()) return aSeq._retn();
+
+
+  Handle(TColStd_HSequenceOfInteger) aHSeq =
+    GetOperations()->GetSameIDs(aShapeWhere, aShapeWhat);
+
+  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();
+}
index cd1a5756ea295c0042e5d611d878044ed7bdda3c..c01b6317e7b4c2a891c4375c3e78262d9f42c3ce 100644 (file)
@@ -264,6 +264,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i :
   GEOM::GEOM_Object_ptr GetSame (GEOM::GEOM_Object_ptr theShapeWhere,
                                  GEOM::GEOM_Object_ptr theShapeWhat);
 
+  GEOM::ListOfLong* GetSameIDs  (GEOM::GEOM_Object_ptr theShapeWhere,
+                                 GEOM::GEOM_Object_ptr theShapeWhat);
+
   ::GEOMImpl_IShapesOperations* GetOperations()
   { return (::GEOMImpl_IShapesOperations*)GetImpl(); }
 };
index bfcb487b06186337542010b027f50529bb47de3b..b072e7c736c38da0dde5951a679288214fd6db0d 100644 (file)
@@ -3870,6 +3870,31 @@ class geompyDC(GEOM._objref_GEOM_Gen):
             RaiseIfFailed("GetSame", self.ShapesOp)
             return anObj
 
+
+        ## Get sub-shape indices of theShapeWhere, which is
+        #  equal to \a theShapeWhat.
+        #  @param theShapeWhere Shape to find sub-shape of.
+        #  @param theShapeWhat Shape, specifying what to find.
+        #  @return List of all found sub-shapes indices. 
+        #
+        #  @ref swig_GetSame "Example"
+        def GetSameIDs(self,theShapeWhere, theShapeWhat):
+            """
+            Get sub-shape indices of theShapeWhere, which is
+            equal to theShapeWhat.
+
+            Parameters:
+                theShapeWhere Shape to find sub-shape of.
+                theShapeWhat Shape, specifying what to find.
+
+            Returns:
+                List of all found sub-shapes indices.
+            """
+            anObj = self.ShapesOp.GetSameIDs(theShapeWhere, theShapeWhat)
+            RaiseIfFailed("GetSameIDs", self.ShapesOp)
+            return anObj
+
+
         # end of l4_obtain
         ## @}
 
index 45ce5dece9335330e40ca3f800c1af39c1ca6c98..c34c6bb048cfe2de77b728d09610840cd3acbed7 100644 (file)
@@ -427,14 +427,27 @@ void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool i
     GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
 
     GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
-    for (int i = 0; i < aSubObjects->length(); i++)
+    for ( int i = 0; i < aSubObjects->length(); i++ )
     {
-      GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
-      if (!CORBA::is_nil(aSS)) {
-        CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
-        CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
-        if (aMainIndex >= 0 && aPlaceIndex > 0)
-          myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
+      GEOM::ListOfLong_var aCurrList = aShapesOp->GetSameIDs( myMainObj, aSubObjects[i] );
+      if( aCurrList->length() > 1 ) {
+        //rnv : To Fix the 21561: EDF 2184 GEOM: Group with second shape restriction.
+        //      In case if GetSameIDs(...) method return more then one ID use 
+        //      GetSharedShapes(...) method to get sub-shapes of the second shape.
+        GEOM::ListOfGO_var aSubObjects2 = aShapesOp->GetSharedShapes( myMainObj, aSubObjects[i], getShapeType() );
+        for( int j = 0; j < aSubObjects2->length(); j++ ) {
+          CORBA::Long aMainIndex =  aLocOp->GetSubShapeIndex( myMainObj, aSubObjects2[j] );
+          CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i]);
+          if ( aMainIndex >= 0 && aPlaceIndex > 0 ) {
+            myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
+          }
+        }
+      } else if(aCurrList->length() > 0 ) {
+        CORBA::Long aMainIndex = aCurrList[0];
+        CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex( myInPlaceObj, aSubObjects[i] );
+        if ( aMainIndex >= 0 && aPlaceIndex > 0) {
+          myMain2InPlaceIndices.Bind( aMainIndex, aPlaceIndex );
+        }
       }
     }
   }
@@ -674,7 +687,7 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap
         anEntry.remove(0, index+1);
         int anIndex = anEntry.toInt();
         if (anIndex)
-          theMapIndex.Add(anIndex);
+        theMapIndex.Add(anIndex);
       }
       else // selection among published shapes
       {