0031153: Visualization - Non clear highlighting of selected trihedron elements
authorvsv <vsv@opencascade.com>
Tue, 19 Nov 2019 08:31:46 +0000 (11:31 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 21 Nov 2019 14:43:07 +0000 (17:43 +0300)
AIS_Trihedron - removed extra fields holding highlight styles; standard styles are now used instead;
fixed unexpected modification of global aspects;
fixed unhighligting of selected plane within Shaded trihedron.

AIS_InteractiveContext now sets highlight color to highlight aspects, not only base color to drawer itself.

src/AIS/AIS_InteractiveContext.cxx
src/AIS/AIS_Trihedron.cxx
src/AIS/AIS_Trihedron.hxx

index 1826f14..5d4454d 100644 (file)
@@ -65,13 +65,15 @@ namespace
   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
 
   //! Initialize default highlighting attributes.
-  static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
+  static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
+                                            const Quantity_Color& theColor)
   {
     theDrawer->SetMethod (Aspect_TOHM_COLOR);
     theDrawer->SetDisplayMode (0);
+    theDrawer->SetColor (theColor);
 
-    theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
-    *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
+    theDrawer->SetupOwnShadingAspect();
+    theDrawer->SetupOwnPointAspect();
     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
     *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
@@ -82,6 +84,24 @@ namespace
     *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
     *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
+    theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
+
+    theDrawer->ShadingAspect()->SetColor (theColor);
+    theDrawer->WireAspect()->SetColor (theColor);
+    theDrawer->LineAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
+    theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
+    theDrawer->FreeBoundaryAspect()->SetColor (theColor);
+    theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
+    theDrawer->PointAspect()->SetColor (theColor);
+    for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DP_None; ++aPartIter)
+    {
+      if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
+      {
+        aLineAsp->SetColor (theColor);
+      }
+    }
 
     theDrawer->WireAspect()->SetWidth (2.0);
     theDrawer->LineAspect()->SetWidth (2.0);
@@ -130,30 +150,26 @@ myIsAutoActivateSelMode(Standard_True)
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
     aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
-    aStyle->SetColor (Quantity_NOC_CYAN1);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
     aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
-    aStyle->SetColor (Quantity_NOC_CYAN1);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
-    aStyle->SetColor (Quantity_NOC_GRAY80);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
     aStyle->Link (myDefaultDrawer);
-    initDefaultHilightAttributes (aStyle);
+    initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
-    aStyle->SetColor (Quantity_NOC_GRAY80);
   }
   {
     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
index 7a2936d..f6ed7e1 100644 (file)
@@ -32,6 +32,7 @@
 #include <Prs3d_DatumAspect.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <Prs3d_Projector.hxx>
 #include <Prs3d_ShadingAspect.hxx>
@@ -59,6 +60,8 @@ AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
   myTrihDispMode (Prs3d_DM_WireFrame),
   myComponent (theComponent)
 {
+  myAutoHilight = Standard_False;
+
   // selection priorities
   mySelectionPriority.Bind (Prs3d_DP_None,   5); // complete triedron: priority 5 (same as faces)
   mySelectionPriority.Bind (Prs3d_DP_Origin, 8); // origin: priority 8
@@ -70,6 +73,7 @@ AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
   {
     mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
   }
+  myHiddenLineAspect = new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_EMPTY, 1.0f);
 
   // trihedron labels
   myLabel.Bind (Prs3d_DP_XAxis, "X");
@@ -135,7 +139,6 @@ void AIS_Trihedron::SetSize(const Standard_Real aValue)
   myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
 
   SetToUpdate();
-  UpdatePresentations();
   UpdateSelection();
 }
 
@@ -163,7 +166,6 @@ void AIS_Trihedron::UnsetSize()
   else
   {
     SetToUpdate();
-    UpdatePresentations();
   }
   UpdateSelection();
 }
@@ -310,36 +312,37 @@ void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManag
   aPresentation->Clear();
   const Prs3d_DatumParts aPart = anOwner->DatumPart();
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
-  Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
   if (aPart >= Prs3d_DP_XOYAxis && aPart <= Prs3d_DP_XOZAxis)
   {
     // planes selection is equal in both shading and wireframe mode
-    aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+    aGroup->SetGroupPrimitivesAspect (theStyle->LineAspect()->Aspect());
   }
   else
   {
     if (myTrihDispMode == Prs3d_DM_Shaded)
     {
-      aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect(aPart)->Aspect());
+      aGroup->SetGroupPrimitivesAspect (theStyle->ShadingAspect()->Aspect());
     }
     else
     {
       if (aPart == Prs3d_DP_Origin)
       {
-        aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
+        aGroup->SetGroupPrimitivesAspect (theStyle->PointAspect()->Aspect());
       }
       else
       {
-        aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect(aPart)->Aspect());
+        aGroup->SetGroupPrimitivesAspect(theStyle->LineAspect()->Aspect());
       }
     }
   }
   aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
 
-  if (aPresentation->GetZLayer() != theStyle->ZLayer())
+  const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer();
+  if (aPresentation->GetZLayer() != aLayer)
   {
-    aPresentation->SetZLayer (theStyle->ZLayer());
+    aPresentation->SetZLayer (aLayer);
   }
+
   aPresentation->Highlight (theStyle);
   thePM->AddToImmediateList (aPresentation);
 }
@@ -356,25 +359,22 @@ void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)&
     return;
   }
 
-  Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
   const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
 
-  const Handle(Prs3d_Drawer)& aContextSelStyle = GetContext()->SelectionStyle();
-  const Quantity_Color& aSelectionColor = aContextSelStyle->Color();
+  Handle(Prs3d_Drawer) anAspect = !myHilightDrawer.IsNull() ? myHilightDrawer : GetContext()->SelectionStyle();
   for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
   {
     const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
     Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
     if (aTrihedronOwner.IsNull())
     {
-      thePM->Color (this, aContextSelStyle, 0);
+      thePM->Color (this, anAspect, 0);
       continue;
     }
       
     const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
     Handle(Graphic3d_Group) aGroup;
-    if (mySelectedParts.Contains (aPart)
-    || !myPartToGroup.Find (aPart, aGroup))
+    if (mySelectedParts.Contains (aPart) || !myPartToGroup.Find (aPart, aGroup))
     {
       continue;
     }
@@ -382,27 +382,23 @@ void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)&
     if (aPart >= Prs3d_DP_XOYAxis
      && aPart <= Prs3d_DP_XOZAxis)
     {
-      getHighlightLineAspect()->SetColor (aSelectionColor);
-      aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+      aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
     }
     else
     {
       if (isShadingMode)
       {
-        getHighlightAspect()->SetColor (aSelectionColor);
-        aGroup->SetGroupPrimitivesAspect (getHighlightAspect()->Aspect());
+        aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect()->Aspect());
       }
       else
       {
         if (aPart == Prs3d_DP_Origin)
         {
-          getHighlightPointAspect()->SetColor (aSelectionColor);
-          aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
+          aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
         }
         else
         {
-          getHighlightLineAspect()->SetColor (aSelectionColor);
-          aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+          aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
         }
       }
     }
@@ -426,9 +422,9 @@ void AIS_Trihedron::ClearSelected()
     if (aPart >= Prs3d_DP_XOYAxis
      && aPart <= Prs3d_DP_XOZAxis)
     {
-      aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
+      aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
     }
-    if (isShadingMode)
+    else if (isShadingMode)
     {
       aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
     }
@@ -553,11 +549,8 @@ void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
     myPartToGroup.Bind (aPart, aGroup);
 
-    const Handle(Graphic3d_AspectLine3d)& aLineAspect = anAspect->LineAspect (aPart)->Aspect();
-    aLineAspect->SetType (Aspect_TOL_EMPTY);
-
     aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
-    aGroup->SetGroupPrimitivesAspect (aLineAspect);
+    aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
   }
 }
 
@@ -933,65 +926,3 @@ void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
     myPrimitives.Bind(aPart, aPrims);
   }
 }
-
-// =======================================================================
-// function : getHighlightAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_ShadingAspect) AIS_Trihedron::getHighlightAspect()
-{
-  if (!myHighlightAspect.IsNull())
-    return myHighlightAspect;
-
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-
-  myHighlightAspect = new Prs3d_ShadingAspect();
-  myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
-  myHighlightAspect->SetColor (aHighlightColor);
-
-  Graphic3d_MaterialAspect aHighlightMaterial;
-  aHighlightMaterial.SetColor (aHighlightColor);
-  myHighlightAspect->SetMaterial (aHighlightMaterial);
-
-  return myHighlightAspect;
-}
-
-// =======================================================================
-// function : getHighlightLineAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_LineAspect) AIS_Trihedron::getHighlightLineAspect()
-{
-  if (!myHighlightLineAspect.IsNull())
-    return myHighlightLineAspect;
-
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-
-  Handle(Prs3d_DatumAspect) aDatumAspect = Attributes()->DatumAspect();
-  Handle(Prs3d_LineAspect) aLineAspect = aDatumAspect->LineAspect(Prs3d_DP_XAxis);
-  myHighlightLineAspect = new Prs3d_LineAspect (aHighlightColor, aLineAspect->Aspect()->Type(),
-                                                aLineAspect->Aspect()->Width());
-
-  return myHighlightLineAspect;
-}
-
-// =======================================================================
-// function : getHighlightPointAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_PointAspect) AIS_Trihedron::getHighlightPointAspect()
-{
-  if (!myHighlightPointAspect.IsNull())
-    return myHighlightPointAspect;
-
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-  myHighlightPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, aHighlightColor, 1.0);
-
-  return myHighlightPointAspect;
-}
index e50a34b..06ed48b 100644 (file)
@@ -186,9 +186,6 @@ public:
 
 public:
 
-  //! Disables auto highlighting to use HilightSelected() and HilightOwnerWithColor() overridden methods.
-  virtual Standard_Boolean IsAutoHilight() const Standard_OVERRIDE { return false; }
-
   //! Method which clear all selected owners belonging
   //! to this selectable object ( for fast presentation draw ).
   Standard_EXPORT virtual void ClearSelected() Standard_OVERRIDE;
@@ -248,13 +245,6 @@ protected:
                                          const gp_Dir& theYDir,
                                          const gp_Dir& theZDir);
 
-  //! Returns highlight line aspect , create if it is the first call
-  Handle(Prs3d_ShadingAspect) getHighlightAspect();
-  //! Returns highlight line aspect , create if it is the first call
-  Handle(Prs3d_LineAspect) getHighlightLineAspect();
-  //! Returns highlight line aspect , create if it is the first call
-  Handle(Prs3d_PointAspect) getHighlightPointAspect();
-
 protected:
   Standard_Boolean myHasOwnSize;
   Standard_Boolean myHasOwnTextColor;
@@ -269,10 +259,7 @@ protected:
 
   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_Group)> myPartToGroup;
   NCollection_List<Prs3d_DatumParts> mySelectedParts;
-
-  Handle(Prs3d_ShadingAspect) myHighlightAspect;
-  Handle(Prs3d_LineAspect)    myHighlightLineAspect;
-  Handle(Prs3d_PointAspect)   myHighlightPointAspect;
+  Handle(Graphic3d_AspectLine3d) myHiddenLineAspect;
 
   NCollection_DataMap<Prs3d_DatumParts, Handle(Graphic3d_ArrayOfPrimitives)> myPrimitives;
 };