Salome HOME
Issue #2913: Make selectable original shape instead of substituting compound
authorvsv <vsv@opencascade.com>
Wed, 29 May 2019 07:22:35 +0000 (10:22 +0300)
committervsv <vsv@opencascade.com>
Mon, 3 Jun 2019 10:32:09 +0000 (13:32 +0300)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/ModuleBase/ModuleBase_ResultPrs.h
src/XGUI/XGUI_Selection.cpp

index 11ab42dc67af2d85f29e2814faea8d6f9850fd64..281f8e36cdadde2fa654b1b06e589f4833a08002 100644 (file)
@@ -64,7 +64,7 @@ IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
 //********************************************************************
 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
   : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0),
-  myTransparency(1)
+  myTransparency(1), myIsSubstituted(false)
 {
   std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
   TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
@@ -150,30 +150,44 @@ bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List<TopoDS_Shape
   TopoDS_Compound aCompound;
   BRep_Builder aBBuilder;
   aBBuilder.MakeCompound (aCompound);
+
+  TopoDS_Compound aShownComp;
+  if (myIsSubstituted)
+    aShownComp = TopoDS::Compound(Shape());
+
   // restore hidden shapes if there are not the shapes in parameter container
   NCollection_List<TopoDS_Shape> aVisibleSubShapes;
-  for (NCollection_List<TopoDS_Shape>::Iterator aHiddenIt(myHiddenSubShapes); aHiddenIt.More();
-       aHiddenIt.Next()) {
-    if (!theShapes.Contains(aHiddenIt.Value()))
+  NCollection_List<TopoDS_Shape>::Iterator aHiddenIt(myHiddenSubShapes);
+  for (; aHiddenIt.More(); aHiddenIt.Next()) {
+    if (!theShapes.Contains(aHiddenIt.Value())) {
       aVisibleSubShapes.Append(aHiddenIt.Value());
-    else
-      aBBuilder.Add (aCompound, aHiddenIt.Value());
+    }
+    else {
+      aBBuilder.Add(aCompound, aHiddenIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Remove(aShownComp, aHiddenIt.Value());
+    }
   }
   isModified = !aVisibleSubShapes.IsEmpty();
-  for (NCollection_List<TopoDS_Shape>::Iterator aVisibleIt(aVisibleSubShapes); aVisibleIt.More();
-       aVisibleIt.Next())
-    myHiddenSubShapes.Remove(aVisibleIt.Value());
-
+  NCollection_List<TopoDS_Shape>::Iterator aVisibleIt(aVisibleSubShapes);
+  for (; aVisibleIt.More(); aVisibleIt.Next()) {
+    if (myHiddenSubShapes.Contains(aVisibleIt.Value())) {
+      myHiddenSubShapes.Remove(aVisibleIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Add(aShownComp, aVisibleIt.Value());
+    }
+  }
   // append hidden shapes into internal container if there are not these shapes
-  for (NCollection_List<TopoDS_Shape>::Iterator aShapeIt(theShapes); aShapeIt.More();
-    aShapeIt.Next())
-  {
+  NCollection_List<TopoDS_Shape>::Iterator aShapeIt(theShapes);
+  for (; aShapeIt.More(); aShapeIt.Next()) {
     if (aShapeIt.Value().ShapeType() != TopAbs_FACE) // only face shape can be hidden
       continue;
 
     if (!myHiddenSubShapes.Contains(aShapeIt.Value())) {
       myHiddenSubShapes.Append(aShapeIt.Value());
       aBBuilder.Add (aCompound, aShapeIt.Value());
+      if (!aShownComp.IsNull())
+        aBBuilder.Remove(aShownComp, aShapeIt.Value());
       isModified = true;
     }
   }
@@ -236,16 +250,24 @@ void ModuleBase_ResultPrs::Compute(
   if (aReadyToDisplay) {
     myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
     if (myHiddenSubShapes.IsEmpty() || myOriginalShape.ShapeType() > TopAbs_FACE ) {
-      if (!myOriginalShape.IsNull())
+      if (!myOriginalShape.IsNull()) {
         Set(myOriginalShape);
+        myIsSubstituted = false;
+      }
     }
     else { // convert shape into SHELL
       TopoDS_Compound aCompound;
-      BRep_Builder aBuilder;
-      aBuilder.MakeCompound (aCompound);
-      collectSubShapes(aBuilder, aCompound, myOriginalShape, myHiddenSubShapes);
+      if (!myIsSubstituted) {
+        BRep_Builder aBuilder;
+        aBuilder.MakeCompound(aCompound);
+        collectSubShapes(aBuilder, aCompound, myOriginalShape, myHiddenSubShapes);
+      }
+      else {
+        aCompound = TopoDS::Compound(Shape());
+      }
       bool isEmptyShape = BOPTools_AlgoTools3D::IsEmptyShape(aCompound);
       Set(aCompound);
+      myIsSubstituted = true;
       if (isEmptyShape)
         aReadyToDisplay = false;
     }
index 5faaadf2b53d65901918f2dbd9fbca06daa95e65..f1ad5e1a0c2c588b59fe1d14e3543c1b486361a9 100644 (file)
@@ -107,6 +107,11 @@ public:
   /// \return false if parameter is out of [0, 1]
   Standard_EXPORT bool setHiddenSubShapeTransparency(double theTransparency);
 
+  Standard_EXPORT TopoDS_Shape originalShape() const { return myOriginalShape; }
+
+  Standard_EXPORT bool isSubstituted() const { return myIsSubstituted; }
+
+
   DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape)
 
 protected:
@@ -149,6 +154,8 @@ private:
   /// Original shape of the result object
   TopoDS_Shape myOriginalShape;
 
+  bool myIsSubstituted;
+
   /// Container of original Shape sub shape to be hidden and not selectable
   NCollection_List<TopoDS_Shape> myHiddenSubShapes;
   TopoDS_Compound myHiddenCompound; /// compound of hidden sub shapes
index 9e29e8b1b08bf729dd70ae701143b374d9bef318..09c0c1fcdeac0fed5c74afe8cb119373bcfc30a4 100644 (file)
@@ -205,9 +205,17 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs,
   // for one feature
   Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
   if( !aBRO.IsNull() && aBRO->HasShape() ) {
+    TopoDS_Shape aShape = aBRO->Shape();
+    Handle(ModuleBase_ResultPrs) aPrsObj = Handle(ModuleBase_ResultPrs)::DownCast(aBRO->Selectable());
+    if (!aPrsObj.IsNull()) {
+      if (aPrsObj->isSubstituted()) {
+        if (aPrsObj->Shape().IsSame(aShape))
+          aShape = aPrsObj->originalShape();
+      }
+    }
     // the located method is called in the context to obtain the shape by the SelectedShape()
     // method, so the shape is located by the same rules
-    TopoDS_Shape aShape = aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location());
+    aShape = aShape.Located(aBRO->Location() * aShape.Location());
 #ifdef BEFORE_TRIHEDRON_PATCH
 #ifndef DEBUG_DELIVERY
     if (aShape.IsNull())