]> OCCT Git - occt.git/commitdiff
0032978: Visualization - AIS_ViewController::PickPoint() includes objects invisible...
authorkgv <kgv@opencascade.com>
Sat, 21 May 2022 14:18:43 +0000 (17:18 +0300)
committerkgv <kgv@opencascade.com>
Sat, 21 May 2022 14:25:43 +0000 (17:25 +0300)
SelectMgr_ViewerSelector::TraverseSensitives() now takes into account object's view affinity.
AIS_InteractiveContext::moveTo() - dropped code SelectMgr_AndOrFilter::SetDisabledObjects()
as filtering is now done by selector itself.

ViewAffinity property has been moved to PrsMgr_PresentableObject for simplicity.
Removed redundant map Graphic3d_CView::HiddenObjects().

14 files changed:
src/AIS/AIS_InteractiveContext.cxx
src/AIS/AIS_Manipulator.cxx
src/AIS/AIS_ViewCube.cxx
src/Graphic3d/Graphic3d_CView.cxx
src/Graphic3d/Graphic3d_CView.hxx
src/Graphic3d/Graphic3d_StructureManager.cxx
src/Graphic3d/Graphic3d_StructureManager.hxx
src/IVtkOCC/IVtkOCC_ViewerSelector.cxx
src/PrsMgr/PrsMgr_PresentableObject.cxx
src/PrsMgr/PrsMgr_PresentableObject.hxx
src/PrsMgr/PrsMgr_PresentationManager.cxx
src/SelectMgr/SelectMgr_ViewerSelector.cxx
src/SelectMgr/SelectMgr_ViewerSelector.hxx
tests/v3d/bugs/bug32978 [new file with mode: 0644]

index 1cd4cb8f91115e510c70c1382217d98a211874fc..8bd2d868c474127a40a7dfb6369ce9d16f00621e 100644 (file)
@@ -362,7 +362,7 @@ void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive&  theListOfIO
       continue;
     }
 
-    Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
+    Handle(Graphic3d_ViewAffinity) anAffinity = anObjIter.Key()->ViewAffinity();
     const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
     if (isVisible == theIsVisibleInView)
     {
@@ -402,17 +402,9 @@ void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject
     return;
   }
 
-  Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
+  Handle(Graphic3d_ViewAffinity) anAffinity = theIObj->ViewAffinity();
   Handle(Graphic3d_CView) aViewImpl = theView->View();
   anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
-  if (theIsVisible)
-  {
-    theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
-  }
-  else
-  {
-    theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
-  }
 }
 
 //=======================================================================
@@ -445,7 +437,8 @@ void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIO
   if (!myObjects.IsBound (theIObj))
   {
     setObjectStatus (theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
-    myMainVwr->StructureManager()->RegisterObject (theIObj);
+    theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
+    myMainVwr->StructureManager()->RegisterObject (theIObj, theIObj->ViewAffinity());
     myMainPM->Display(theIObj, theDispMode);
     if (theSelectionMode != -1)
     {
@@ -521,7 +514,8 @@ void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
     Standard_Integer aDispMode, aHiMod, aSelModeDef;
     GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
     setObjectStatus (theIObj, PrsMgr_DisplayStatus_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
-    myMainVwr->StructureManager()->RegisterObject (theIObj);
+    theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
+    myMainVwr->StructureManager()->RegisterObject (theIObj, theIObj->ViewAffinity());
   }
 
   // Register theIObj in the selection manager to prepare further activation of selection
@@ -1900,13 +1894,9 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
   mgrSelector->Remove (anObj);
 
   setObjectStatus (theIObj, PrsMgr_DisplayStatus_None, -1, -1);
+  theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
   myMainVwr->StructureManager()->UnregisterObject (theIObj);
 
-  for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
-  {
-    aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
-  }
-
   if (!myLastPicked.IsNull())
   {
     if (myLastPicked->IsSameSelectable (theIObj))
@@ -2228,7 +2218,7 @@ Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection (const Handle(V3d_View)&
       continue;
     }
 
-    Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObj);
+    Handle(Graphic3d_ViewAffinity) anAffinity = anObj->ViewAffinity();
     const Standard_Boolean isVisible = aViewId == -1 || anAffinity->IsVisible (aViewId);
     if (!isVisible)
     {
@@ -2682,12 +2672,10 @@ AIS_StatusOfDetection AIS_InteractiveContext::moveTo (const Handle(V3d_View)& th
   myDetectedSeq.Clear();
   myLastActiveView = theView.get();
 
-  // preliminaires
+  // preliminaries
   AIS_StatusOfDetection aStatus        = AIS_SOD_Nothing;
   Standard_Boolean      toUpdateViewer = Standard_False;
 
-  myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
-
   // filling of myAISDetectedSeq sequence storing information about detected AIS objects
   // (the objects must be AIS_Shapes)
   const Standard_Integer aDetectedNb = MainSelector()->NbPicked();
index 05aefddb1fed87bf343deaba02ac6b6455299f08..43da955306944c2a47ed47b0bd758c7fada5684c 100644 (file)
@@ -1071,7 +1071,7 @@ void AIS_Manipulator::HilightOwnerWithColor (const Handle(PrsMgr_PresentationMan
     return;
   }
 
-  aPresentation->CStructure()->ViewAffinity = thePM->StructureManager()->ObjectAffinity (Handle(Standard_Transient) (this));
+  aPresentation->CStructure()->ViewAffinity = myViewAffinity;
 
   if (anOwner->Mode() == AIS_MM_TranslationPlane)
   {
index d2ec561fc1728b687a721ac62759779d37e42d95..25894e1057c5ca128362e158d0b9f2f0bcacb949 100644 (file)
@@ -1016,7 +1016,7 @@ void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManage
 
   Handle(Prs3d_Presentation) aHiPrs = GetHilightPresentation (thePrsMgr);
   aHiPrs->Clear();
-  aHiPrs->CStructure()->ViewAffinity = thePrsMgr->StructureManager()->ObjectAffinity (Handle(Standard_Transient)(this));
+  aHiPrs->CStructure()->ViewAffinity = myViewAffinity;
   aHiPrs->SetTransformPersistence (TransformPersistence());
   aHiPrs->SetZLayer (aLayer);
 
index c114c66a214fd95f475f48be247f58323913b538..985692f00cba09e3682a861316ed6cf81109d957 100644 (file)
@@ -36,7 +36,6 @@ Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theM
   //
   myStructureManager (theMgr),
   myCamera (new Graphic3d_Camera()),
-  myHiddenObjects (new Graphic3d_NMapOfTransient()),
   myIsInComputedMode (Standard_False),
   myIsActive (Standard_False),
   myIsRemoved (Standard_False),
index ac687ce8f4a42dba5df74fd91fac9656b6bac904..143b50f4c485bf61a2129e44115a5f3b71e7f588 100644 (file)
@@ -134,12 +134,6 @@ public:
   //! Returns number of displayed structures in the view.
   virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
 
-  //! Returns map of objects hidden within this specific view (not viewer-wise).
-  const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; }
-
-  //! Returns map of objects hidden within this specific view (not viewer-wise).
-  Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; }
-
   //! Returns Standard_True in case if the structure with the given <theStructId> is
   //! in list of structures to be computed and stores computed struct to <theComputedStruct>.
   Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
@@ -649,7 +643,6 @@ protected:
   Graphic3d_SequenceOfStructure myStructsToCompute;
   Graphic3d_SequenceOfStructure myStructsComputed;
   Graphic3d_MapOfStructure myStructsDisplayed;
-  Handle(Graphic3d_NMapOfTransient) myHiddenObjects;
   Standard_Boolean myIsInComputedMode;
   Standard_Boolean myIsActive;
   Standard_Boolean myIsRemoved;
index de8637203c33b823d17a701b1023333c33d7312e..a4e45a9b012145d3ae5f98a6bfe1b6c21f150a84 100644 (file)
@@ -182,29 +182,45 @@ void Graphic3d_StructureManager::RecomputeStructures (const NCollection_Map<Grap
   }
 }
 
-Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject)
+// ========================================================================
+// function : RegisterObject
+// purpose  :
+// ========================================================================
+void Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject,
+                                                 const Handle(Graphic3d_ViewAffinity)& theAffinity)
 {
   Handle(Graphic3d_ViewAffinity) aResult;
-  if (myRegisteredObjects.Find (theObject.operator->(), aResult))
+  if (myRegisteredObjects.Find (theObject.operator->(), aResult)
+   && aResult == theAffinity)
   {
-    return aResult;
+    return;
   }
 
-  aResult = new Graphic3d_ViewAffinity();
-  myRegisteredObjects.Bind (theObject.operator->(), aResult);
-  return aResult;
+  myRegisteredObjects.Bind (theObject.operator->(), theAffinity);
 }
 
+// ========================================================================
+// function : UnregisterObject
+// purpose  :
+// ========================================================================
 void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject)
 {
   myRegisteredObjects.UnBind (theObject.operator->());
 }
 
-Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
+// ========================================================================
+// function : ObjectAffinity
+// purpose  :
+// ========================================================================
+const Handle(Graphic3d_ViewAffinity)& Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const
 {
-  Handle(Graphic3d_ViewAffinity) aResult;
-  myRegisteredObjects.Find (theObject.operator->(), aResult);
-  return aResult;
+  const Handle(Graphic3d_ViewAffinity)* aResult = myRegisteredObjects.Seek (theObject.operator->());
+  if (aResult == nullptr)
+  {
+    static const Handle(Graphic3d_ViewAffinity) aDummy;
+    return aDummy;
+  }
+  return *aResult;
 }
 
 // ========================================================================
index e1dd1452ac79c572e391b05cf19ec7343ceba63b..1a881d198008434a56472dae32666b61552735cc 100644 (file)
@@ -151,11 +151,12 @@ public:
   //! Recomputes all structures from theStructures.
   Standard_EXPORT void RecomputeStructures (const NCollection_Map<Graphic3d_Structure*>& theStructures);
 
-  Standard_EXPORT Handle(Graphic3d_ViewAffinity) RegisterObject (const Handle(Standard_Transient)& theObject);
+  Standard_EXPORT void RegisterObject (const Handle(Standard_Transient)& theObject,
+                                       const Handle(Graphic3d_ViewAffinity)& theAffinity);
 
   Standard_EXPORT void UnregisterObject (const Handle(Standard_Transient)& theObject);
 
-  Standard_EXPORT Handle(Graphic3d_ViewAffinity) ObjectAffinity (const Handle(Standard_Transient)& theObject) const;
+  Standard_EXPORT const Handle(Graphic3d_ViewAffinity)& ObjectAffinity (const Handle(Standard_Transient)& theObject) const;
 
   //! Returns TRUE if Device Lost flag has been set and presentation data should be reuploaded onto graphics driver.
   Standard_Boolean IsDeviceLost() const { return myDeviceLostFlag; }
index f3c124cae65888d2e2932cdfdfc1200cedb1d146..f12b8723a679415fa4a5d36ad7ec338619978373 100644 (file)
@@ -114,7 +114,7 @@ void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXPix,
 
   mySelectingVolumeMgr.BuildSelectingVolume();
 
-  TraverseSensitives();
+  TraverseSensitives (-1);
 }
 
 //============================================================================
@@ -160,7 +160,7 @@ void IVtkOCC_ViewerSelector::Pick (const Standard_Integer    theXMin,
 
   mySelectingVolumeMgr.BuildSelectingVolume();
 
-  TraverseSensitives();
+  TraverseSensitives (-1);
 }
 
 //============================================================================
@@ -207,7 +207,7 @@ void IVtkOCC_ViewerSelector::Pick (double**                  thePoly,
 
   mySelectingVolumeMgr.BuildSelectingVolume();
 
-  TraverseSensitives();
+  TraverseSensitives (-1);
 }
 
 //============================================================================
index 835dadb20c2f35a11faca1e7fbdd4c993838c2f5..3cb38867de921ec0dca51efbf21d21a51bb0918c 100644 (file)
@@ -45,6 +45,7 @@ const gp_Trsf& PrsMgr_PresentableObject::getIdentityTrsf()
 //=======================================================================
 PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentation3d theType)
 : myParent (NULL),
+  myViewAffinity (new Graphic3d_ViewAffinity()),
   myDrawer (new Prs3d_Drawer()),
   myTypeOfPresentation3d (theType),
   myDisplayStatus (PrsMgr_DisplayStatus_None),
index 3002dc5ebf0a70c73959db836b06896f859c89d7..8e75fbf3698798a79d9c885711be9b3cc82202b7 100644 (file)
@@ -74,6 +74,9 @@ public:
   //! This method should be called before object displaying to take effect.
   Standard_EXPORT virtual void SetMutable (const Standard_Boolean theIsMutable);
 
+  //! Return view affinity mask.
+  const Handle(Graphic3d_ViewAffinity)& ViewAffinity() const { return myViewAffinity; }
+
   //! Returns true if the Interactive Object has display mode setting overriding global setting (within Interactive Context).
   Standard_Boolean HasDisplayMode() const { return myDrawer->DisplayMode() != -1; }
 
@@ -522,6 +525,7 @@ protected:
 
   PrsMgr_PresentableObject*              myParent;                  //!< pointer to the parent object
   PrsMgr_Presentations                   myPresentations;           //!< list of presentations
+  Handle(Graphic3d_ViewAffinity)         myViewAffinity;            //!< view affinity mask
   Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;              //!< sequence of object-specific clipping planes
   Handle(Prs3d_Drawer)                   myDrawer;                  //!< main presentation attributes
   Handle(Prs3d_Drawer)                   myHilightDrawer;           //!< (optional) custom presentation attributes for highlighting selected object
index 915e1b9fd7032ee945a4553d81cb94bd4a9cdae9..766d70ed2a09523190fa828ff11c2482a2bc1cef 100644 (file)
@@ -519,7 +519,7 @@ Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Hand
 
   Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj, theMode);
   aPrs->SetZLayer (thePrsObj->ZLayer());
-  aPrs->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
+  aPrs->CStructure()->ViewAffinity = !theSelObj.IsNull() ? theSelObj->ViewAffinity() : thePrsObj->ViewAffinity();
   thePrsObj->Presentations().Append (aPrs);
   thePrsObj->Fill (this, aPrs, theMode);
 
index 8559eaed3accaf8634c3eae9346ced936693fb2c..94a7e75d75a66250d96b2aca849cee458615bcde 100644 (file)
@@ -626,7 +626,7 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable
 // purpose : Traverses BVH containing all added selectable objects and
 //           finds candidates for further search of overlap
 //=======================================================================
-void SelectMgr_ViewerSelector::TraverseSensitives()
+void SelectMgr_ViewerSelector::TraverseSensitives (const Standard_Integer theViewId)
 {
   SelectMgr_BVHThreadPool::Sentry aSentry (myBVHThreadPool);
 
@@ -750,14 +750,16 @@ void SelectMgr_ViewerSelector::TraverseSensitives()
       }
       else
       {
-        Standard_Integer aStartIdx = aBVHTree->BegPrimitive (aNode);
-        Standard_Integer anEndIdx  = aBVHTree->EndPrimitive (aNode);
+        const Standard_Integer aStartIdx = aBVHTree->BegPrimitive (aNode);
+        const Standard_Integer anEndIdx  = aBVHTree->EndPrimitive (aNode);
         for (Standard_Integer anIdx = aStartIdx; anIdx <= anEndIdx; ++anIdx)
         {
-          const Handle(SelectMgr_SelectableObject)& aSelectableObject =
-            mySelectableObjects.GetObjectById (aBVHSubset, anIdx);
-
-          traverseObject (aSelectableObject, aMgr, aCamera, aProjectionMat, aWorldViewMat, aWinSize);
+          const Handle(SelectMgr_SelectableObject)& aSelObj = mySelectableObjects.GetObjectById (aBVHSubset, anIdx);
+          const Handle(Graphic3d_ViewAffinity)& aViewAffinity = aSelObj->ViewAffinity();
+          if (theViewId == -1 || aViewAffinity->IsVisible (theViewId))
+          {
+            traverseObject (aSelObj, aMgr, aCamera, aProjectionMat, aWorldViewMat, aWinSize);
+          }
         }
         if (aHead < 0)
         {
@@ -1175,7 +1177,7 @@ void SelectMgr_ViewerSelector::Pick (const Standard_Integer theXPix,
   mySelectingVolumeMgr.BuildSelectingVolume();
   mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes(), Handle(Graphic3d_SequenceOfHClipPlane)(), NULL);
 
-  TraverseSensitives();
+  TraverseSensitives (theView->View()->Identification());
 }
 
 //=======================================================================
@@ -1204,7 +1206,7 @@ void SelectMgr_ViewerSelector::Pick (const Standard_Integer theXPMin,
 
   mySelectingVolumeMgr.BuildSelectingVolume();
   mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes(), Handle(Graphic3d_SequenceOfHClipPlane)(), NULL);
-  TraverseSensitives();
+  TraverseSensitives (theView->View()->Identification());
 }
 
 //=======================================================================
@@ -1224,7 +1226,7 @@ void SelectMgr_ViewerSelector::Pick (const TColgp_Array1OfPnt2d& thePolyline,
   mySelectingVolumeMgr.BuildSelectingVolume();
   mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes(), Handle(Graphic3d_SequenceOfHClipPlane)(), NULL);
 
-  TraverseSensitives();
+  TraverseSensitives (theView->View()->Identification());
 }
 
 //=======================================================================
@@ -1240,7 +1242,7 @@ void SelectMgr_ViewerSelector::Pick (const gp_Ax1& theAxis,
   mySelectingVolumeMgr.BuildSelectingVolume();
   mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes(), Handle(Graphic3d_SequenceOfHClipPlane)(), NULL);
 
-  TraverseSensitives();
+  TraverseSensitives (theView->View()->Identification());
 }
 
 //=======================================================================
index e46d76a06da4b88bffaf16922f2f7620945e8b2c..ad684245d13981ab5d1fe52f37ae122d25964a0e 100644 (file)
@@ -325,7 +325,7 @@ protected:
 
   //! Traverses BVH containing all added selectable objects and
   //! finds candidates for further search of overlap
-  Standard_EXPORT void TraverseSensitives();
+  Standard_EXPORT void TraverseSensitives (const Standard_Integer theViewId = -1);
 
   //! Internal function that checks if there is possible overlap between some entity of selectable object theObject and
   //! current selecting volume.
diff --git a/tests/v3d/bugs/bug32978 b/tests/v3d/bugs/bug32978
new file mode 100644 (file)
index 0000000..f532c57
--- /dev/null
@@ -0,0 +1,34 @@
+puts "============"
+puts "0031965: Visualization - AIS_InteractiveContext::HilightWithColor() ignores passed highlight style"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+vinit V1/RootView -width 1024 -height 512 -composer 0
+vbackground GRAY20
+
+vinit V2/ViewLeft -parent V1/RootView -width 0.5 -height 1.0
+vbackground GRAY30
+
+box b 100 200 300
+vdisplay -dispMode 1 b
+vaspects b -faceBoundaryDraw 1
+vfit
+vviewcube vc
+
+vinit V2/ViewRight -parent V1/RootView -width 0.5 -height 1.0 -left 0.5
+vbackground GRAY40
+psphere s 300
+vdisplay -dispMode 1 s
+vaspects s -material SILVER
+vfit
+vzbufftrihedron
+
+vactivate V2/ViewLeft
+verase s -view
+vcamera -rotationMode pick
+vmoveto 100 100
+if { [string match "*Select3D_SensitiveSphere*" [vstate -entities]] } { puts "Error: sphere should NOT be detected" }
+
+vseldump $::imagedir/${::casename}_sel.png -type entity
+vdump $::imagedir/${::casename}_vis.png