Show/Hide a selection

Hi,

I display a Shape (myShape) using an AIS_Shape (myAISShape) in a context (myInteractiveContext)
I open a local context for selection of TopoDS_Face, as shown in OCC documentation. Then I get the selected faces using that kind of code :

for (myInteractiveContext->InitSelected();
myInteractiveContext->MoreSelected();
myInteractiveContext->NextSelected())
{
TopoDS_Shape SelectedShape = myInteractiveContext->SelectedShape();
}

Everything goes fine up to here...

BUT, I'd like to hide, in the viewer, the selected faces. It seems (at least to me !) not a very complex task, but I could not find a way to do this....

I've investigated quite a long time, and it seems that it is not possible to get the InteractiveObject which owns the Selected face.

For instance, something like this :

for(myInteractiveContext->InitSelected();myInteractiveContext->MoreSelected();myInteractiveContext->NextSelected())
myInteractiveContext->Erase(myInteractiveContext->SelectedInteractive());

seems to erase myAISShape completely ! (and not only the 'selected interactive ' face....)

I've also tried to get the TopoDS_HShape of the selected face, and set its owner to a non displayed AISShape using that kind of code :

for(myInteractiveContext->InitSelected();myInteractiveContext->MoreSelected();myInteractiveContext->NextSelected())
{
Handle_TopoDS_HShape H_TDSShape = new TopoDS_HShape(myInteractiveContext->SelectedShape());

myHiddenAISShape->SetOwner(H_TDSShape);

}

This does not work either... :-(

Can someone tell we (first) if there is a chance to be able to get the interactiveobject related to the selection in a local context (to call Erase() on it thus hiding the selected part of the shape) ?

If it is not possible (As I now fear it), how could I hide my selectio n ? Could anyone could at least give me a clue because I have no more idea to achieve this...

Thanks in advance,
Francois

Roman Lygin's picture

Hello Francois,

When you display an interactive object (AIS_Shape in particular) and then open local context for selection of its SUB(!)-faces, showing/hiding will of course work on those SUB-faces only (which are displayed OVER initial object). Obviously, it's impossibe to display a box and in local context to select and hide the top face expecting the box becomes consisting of 5 remaining faces.
Your AIS_Shape corresponds to the TopoDS_Shape and mapping is consistent (if no change in TopoDS_Shape - no change in AIS_Shape either).

What you can do is to implement a behavior on your own - either updating TopoDS_Shape removing/restoring faces, or by custom interactive object that would allow distinction from its underlying topology. Another straighforward way that comes to my mind is to display faces independently and then select/hide/show them, if your only objective is visualization. However even in this case, performance may suffer from having many individual objects instead of a single.

Hope this description will help you.
Good luck.

Roman

colorviz's picture

Thanks a lot Roman for your help ! I understand better what's wrong with my code...

In fact, I wanted to hide faces to solve another problem :

If I have a TopoDS_Shape which is for instance made of two concentric spheres, it is not possible to select the inside sphere. So I wanted to hide some faces (eg external sphere) to be able to select the inside one. But maybe there is a smarter way to enable selection of those "internal" faces (which cannot be highlighted otherwise)...

Is it possible to enable/disable selection of a part of the AIS_Shape ? Is there another smart way to solve this ?

Thanks in advance,
Francois

Roman Lygin's picture

Hi Francois,

It's quite a specific case and frankly I don't have a straightforward answer but I'm quite sure it's possible. What I guess you need is to disable external sphere selection. What you might do is start from AIS_InteractiveContex::Load(), ::Deactivate() and using custom selection filters (Visualization User's Guide may help).

Let the forum know if you accomplish your objective.

Good luck !
Roman

Sharjith Naramparambath's picture

Hi,

One possible solution for selecting any shape in such situation could be by maintaining a list or tree in the gui of the application. This tree is populated with object names as you create them. You may have to make a custom class derived from AIS_Shape and maintain a naming system within for the object with querrying facilities. When the user selects any name (string) from the tree view, the string can be matched with the name of the displayed shape by iterating the context and then the matched object can be loaded into selection by AIS_InteractiveContex::Load(). You can also maintain the backward relation of hilighting the tree element when the selection is done thru screen. That is how commercial CAD packages do. Hope you will be able to implement it.

Regards
N. Sharjith

lantheaume flore's picture

Hi Francois,

If I have understood your problem, you want to select a face that is not hilighted by the selection process, because this face is inside an other shape.

Maybe you could use the methods HasNextDetected and HilightNextDetected of the AIS_InteractiveContext, that you could branch on the right arrow key.
I've already done it, long time ago. It works fine but only when a local context is opened.
I think that this solution could solve your problem on a simple way.

Flore