Custom AIS_InteractiveObject: different presentation when hilighted

Hello everyone,

I'm trying to inherit from AIS_InteractiveObject in order to create a new object (usinig OCC 7.3.0)

I've seen that, implementing properly the Compute() method I can build its presentation as desired (more or less).

Of course I will vary its aspect according to "theMode" parameter in case this is needed.

But one of my goals is also to have a possibly different representation of this interactive object when the mouse passes over it (dynamic hilight) and/or when the object is selected: of course, by changing the properties for drawer associated to selection/hilight mechanism is a way, but this doesn't change its aspect very much as, I guess, only color, thickness, material, transparency and so on will be affected. How will I, for instance, get my object to look like a box (its bounding box, for instance) instead of a sphere or a 3D wire? I thought that this can be achieved with a certain usage of Compute method, but I don't remember how...

Many thanks in advance

Gianluca

Kirill Gavrilov's picture

The simplest way is using different Display Mode for main presentation and highlighting. For that you need redefining AIS_InteractiveObject::Compute() to handle different Display Modes and choose one for highlighting - see AIS_InteractiveObject::SetDisplayMode() and AIS_InteractiveObject::SetHilightMode().

This is how AIS_Shape behaves by default, when the main presentation is AIS_Shaded (1) and highlighting is AIS_Wireframe (0).

Gianluca Antoniacci's picture

Hello Kirill,

many thanks for your answer.

As a matter of fact I was able to remember this approach and managed to gete a different representation for my object.

I still have many questions about this:

  • I understood that SetHilightMode() is now obsolete and that a HilightDrawer and a DynamicHilightDrawer are to be used instead. But if I set two drawer for my newly created object, the custom selection mechanism doesn't seem to work anymore. Am I doing something wrong or is just the confusion in my head (and lack of knowledge) the actual problem here?
  • Using a new drawer each time I'm entering the compute method (it seems to be corrupted if created once and for all within the constructor of my object) I managed to get a different representation when selecting/hilighting it: how can I force its color to be as desired? The shape is correct but the coloro is always cyan when hilighted and "almost wite" when selected. How come?
  • as you can see fromo the attached picture, both representations are shown: I expected them to be mutually exclusive...
  • Here is a snipped of my code (I'm using C# wrapper with OCC 7.3.0):

public override void Compute(PrsMgr_PresentationManager thePrsMgr, Prs3d_Presentation thePrs, int theMode)
        {           
            thePrs.Clear();
            if (theMode == 3)
            {
                for (int i = 0; i < _centers.Count; i++)
                {
                    gp_Pnt curCenter = _centers[i];
                    double curRadius = _radii[i];
                    BRepPrimAPI_MakeSphere sphereMk = new BRepPrimAPI_MakeSphere(curCenter, curRadius);
                    StdPrs_ShadedShape.Add(thePrs, sphereMk.Shape(), Attributes());
                }
            }
            else if (theMode == 0)
            {
                Prs3d_Drawer dynamicHilightDrawer = new Prs3d_Drawer();
                dynamicHilightDrawer.SetColor(new Quantity.Quantity_Color(Quantity.Quantity_NameOfColor.Quantity_NOC_BLUE1));
                Prs3d_LineAspect lineAspect = dynamicHilightDrawer.LineAspect();
                lineAspect.SetAspect(new Graphic3d_AspectLine3d(new Quantity.Quantity_Color(Quantity.Quantity_NameOfColor.Quantity_NOC_BLUE1), Aspect.Aspect_TypeOfLine.Aspect_TOL_DASH, 3));
                dynamicHilightDrawer.SetLineAspect(lineAspect);
                for (int i = 0; i < _centers.Count; i++)
                {

// for some reasons, here the list of gp_Pnt is not consisten any longer and I get a null exception!!! 
                    //gp_Pnt curCenter = _centers[i];
                    gp_Pnt curCenter = new gp_Pnt(_xList[i], _yList[i], _zList[i]);
                    double curRadius = _radii[i];
                    Bnd.Bnd_Box bb = new Bnd.Bnd_Box();
                    bb.SetVoid();
                    double x = _xList[i];
                    double y = _yList[i];
                    double z = _zList[i];
                    bb.Update(x - curRadius, y - curRadius, z - curRadius, x + curRadius, y + curRadius, z + curRadius);
                    StdPrs_BndBox.Add(thePrs, bb, dynamicHilightDrawer);
                }
            }

Many thanks again

Gianluca

Attachments: