Enable/Disable highlight under mouse

devdscm

CAD practitioner
Hello,
I am playing around a very basic your lesson "Lesson_04_HelloOpencascade" , because I have to fix some important concepts.
I have compiled and runned the application (see Imagine 1)
When I move the mouse over the shapes : Because of "m_context->Activate(4, true);" calling , then face outline under mouse is highlighted (cyan color) (see Imagine 2 / 3)
Now , my unresolved questions are :
1. I want be able to disable highlight of outline face. What's the way to do this? ( or better , I would like decide at runtime - for example clicking on toolbar button - if enable or disable the highlight . In some cases it can be useful, in other cases it is not
2. Is there a way to change default highlight color ( cyan) ?
I checked that in the function AdjustSelectionStyle ( AIS_Interactive_context) are improved functions acting on AIS_InteractiveContext , but I was not able find way to get results for question 1 and 2
Thanks in advance.
 

Attachments

  • Immagine1.png
    Immagine1.png
    12.7 KB · Views: 2
  • Immagine2.png
    Immagine2.png
    10.2 KB · Views: 2
  • Immagine3.png
    Immagine3.png
    16.6 KB · Views: 2

natalia

Moderator
Staff member
Hello @devdscm

1. To disable highlight of face’s lines (type ‘4), use the next call:
C++:
selDrawer->SetFreeBoundaryDraw(false);

To disable highlight of edge’s lines, use the next call:
C++:
selDrawer->SetWireDraw(false);

2. Yes, sure, just use methods for setting color like it’s in the mentioned Lesson.

Why it’s not working using AdjustSelectionStyle method of the lesson.
It's because you're expecting apply of this change to another kind of selection style.
Just set selection style for another enum: ‘Prs3d_TypeOfHighlight_LocalDynamic’ (instead of used in the lesson). AIS allows having different styles for different selection/highlight behaviour.
Also, it might be useful playing with style of display mode for drawer, some selection might be in shading another in wireframe if you'd like).

Below, I’m attaching changed method of the ‘AdjustSelectionStyle’ where the highlight is hidden for both, face bounds and edges, but selection is in shading mode (sorry, it's just a draft with copy-paste the same code):
Code:
  void AdjustSelectionStyle(const Handle(AIS_InteractiveContext)& context)
  {
    {
      // Initialize style for sub-shape selection.
      Handle(Prs3d_Drawer) selDrawer = new Prs3d_Drawer;
      //
      selDrawer->SetLink                ( context->DefaultDrawer() );
      selDrawer->SetFaceBoundaryDraw    ( true );
      selDrawer->SetDisplayMode         ( 1 ); // Shaded
      selDrawer->SetTransparency        ( 0.5f );
      selDrawer->SetZLayer              ( Graphic3d_ZLayerId_Topmost );
      selDrawer->SetColor               ( Quantity_NOC_GOLD );
      selDrawer->SetBasicFillAreaAspect ( new Graphic3d_AspectFillArea3d() );

      // Adjust fill area aspect.
      const Handle(Graphic3d_AspectFillArea3d)&
        fillArea = selDrawer->BasicFillAreaAspect();
      //
      fillArea->SetInteriorColor     (Quantity_NOC_GOLD);
      fillArea->SetBackInteriorColor (Quantity_NOC_GOLD);
      //
      fillArea->ChangeFrontMaterial() .SetMaterialName(Graphic3d_NOM_NEON_GNC);
      fillArea->ChangeFrontMaterial() .SetTransparency(0.4f);
      fillArea->ChangeBackMaterial()  .SetMaterialName(Graphic3d_NOM_NEON_GNC);
      fillArea->ChangeBackMaterial()  .SetTransparency(0.4f);

      selDrawer->UnFreeBoundaryAspect()->SetWidth(1.0);

      // Update AIS context.
      context->SetHighlightStyle(Prs3d_TypeOfHighlight_LocalSelected, selDrawer);
    }
    {
      // Initialize style for sub-shape selection.
      Handle(Prs3d_Drawer) selDrawer = new Prs3d_Drawer;
      //
      selDrawer->SetLink                ( context->DefaultDrawer() );
      selDrawer->SetFaceBoundaryDraw    ( true );
      // change 1: to hide faces outlines
      selDrawer->SetFreeBoundaryDraw(false);
      selDrawer->SetWireDraw(false);
      // end change 1
      // change 2: to enable wireframe display mode instead of shading
      selDrawer->SetDisplayMode         ( 0/*1*/ ); // Wireframe
      // end of change 2
      selDrawer->SetTransparency        ( 0.5f );
      selDrawer->SetZLayer              ( Graphic3d_ZLayerId_Topmost );
      selDrawer->SetColor               ( Quantity_NOC_GREEN/*GOLD*/ );
      selDrawer->SetBasicFillAreaAspect ( new Graphic3d_AspectFillArea3d() );

      // Adjust fill area aspect.
      const Handle(Graphic3d_AspectFillArea3d)&
        fillArea = selDrawer->BasicFillAreaAspect();
      //
      fillArea->SetInteriorColor     (Quantity_NOC_GOLD);
      fillArea->SetBackInteriorColor (Quantity_NOC_GOLD);
      //
      fillArea->ChangeFrontMaterial() .SetMaterialName(Graphic3d_NOM_NEON_GNC);
      fillArea->ChangeFrontMaterial() .SetTransparency(0.4f);
      fillArea->ChangeBackMaterial()  .SetMaterialName(Graphic3d_NOM_NEON_GNC);
      fillArea->ChangeBackMaterial()  .SetTransparency(0.4f);

      selDrawer->UnFreeBoundaryAspect()->SetWidth(1.0);

      // Update AIS context.
      // change 3: another style type is modified here
      context->SetHighlightStyle(Prs3d_TypeOfHighlight_LocalDynamic, selDrawer);
      // end of change 3
    }
  }
 

devdscm

CAD practitioner
ok,thanks for reply.
Just a last question: when I activate TopAbs_EDGE (to select EDGES) , the lines behind the faces are drawn as well.
Is there an easy way to hide those edges?
 

Attachments

  • Immagine4.png
    Immagine4.png
    8.8 KB · Views: 2
  • Immagine5.png
    Immagine5.png
    8.4 KB · Views: 2

natalia

Moderator
Staff member
Let me first give some words about why it happens. What happens when you activate ‘edges’ selection mode only in the context? Active selection contains lots owners with the edges inside. There is no any overlapping geometry in active selection due to selection contains only edges. As a result, invisible edges are also highlighted and available for selecting.

One of possible solution here might be to activate the object in the solid/face local selection mode and to filter this type of topology to be not selectable/highlighted. In this case, the first detected object will be the solid but it can not be highlighted due to the filter.

Which steps should be done in the sample to try this:

- Add activation of the presentation in ‘solid’ mode (or ‘face’ as it was):
C++:
// Activate selection modes.
m_context->Activate(6, true); // solid
m_context->Activate(2, true); // edges

- Now we need set filter to context to select only edges:
C++:
// AIS context.
m_context = new AIS_InteractiveContext(m_viewer);
m_context->AddFilter(new StdSelect_ShapeTypeFilter(TopAbs_ShapeEnum::TopAbs_EDGE));

And, finally, we should specify picking strategy to process only top most detected selection owners:
C++:
m_context->SetPickingStrategy(SelectMgr_PickingStrategy_OnlyTopmost);
 
Top