display: how to hide a face within an AISColored shape

Forums: 

Dear all, I'm quite new to pythonOCC, so let me apologize if my question will results trivial for the experts. I'm trying to develop a tool in which the user can select different faces of an object. I would like also to include a function to hide some selected faces. Unfortunately, after several attempts, I did not found a way to hide a face within an AIS_ColoredShape.

As a trick, I make transparent the faces I would like to hide, but it is not a real solution, as even if the transparent faces are not visible, they are still there and, for example, can be selected, or they hinder the selection of the face that stand behind.

You can find attached an example of the code I used. Have you got any suggestions?

Attachments: 
Kirill Gavrilov's picture

AIS_ColoredShape has no direct method for setting hidden flag, but AIS_ColoredDrawer does - so that XCAFPrs_AISObject is able to apply a hidden attribute from imported STEP model. In C++ the code might look like this:

TopoDS_Shape theSubShape;
Handle(AIS_ColoredShape) thePrs;

Handle(AIS_ColoredDrawer) aDrawer = thePrs->CustomAspects (theSubShape);
aDrawer->SetHidden (true);
Matteo Giovannini's picture

Dear Kirill,
thank you very much for your kind reply.
I have just implemented your suggestion in the example as follow:

def hide(Surface):
global hidden_surfaces
global context
global aisShape
hidden_surfaces.append(aSurface)
print("aSurface was hidden")
print(type(aSurface))
print('')
aDrawer=aisShape.CustomAspects(aSurface)
aDrawer.SetHidden(True)
context.HilightWithColor(aisShape, drawer, True)

It does hide surfaces, as they are no more visible on the screen. However, surfaces are still there and do not allow to select other entities that stand behind them. Probably, I wrongly used "hide" as I would like to erase those faces from the visualization in order to easily manipulate the remaining entities.
At the same time, I need to have a way to restore them by the "Show All" button.
Any ideas about how to do it?

Kirill Gavrilov's picture

Selection and presentation are computed independently in AIS. Your code calls AIS_InteractiveContext::HilightWithColor(), so I guess that object has been already displayed before applying hidden flag. In this case, try something like AIS_InteractiveContext::Redisplay() which should recompute both presentation and selection entities.

Matteo Giovannini's picture

Dear Kirill,
once again thank you very much for your precious comments. You were completely right, calling a "Redisplay" I got what I was looking for, as hidden surfaces are no more nor visible neither selectable. I attach a new version of the example which includes these features in case it may help someone else...

Attachments: