showing/hiding an AIS_Shape

I have a list of ~1000 TopoDS_Shapes i give to an AIS_InteractiveContext at the beginning of the program.
I want to hide/show specific shapes at the user's request.

however, this code for hiding a list of shapes will not work

Handle_TopTools_HSequenceOfShape shapes; //my shapes
Handle_AIS_Shape cur_shape = new AIS_Shape(TopoDS_Shape());

for(integer i = 1; i Length(); ++i)
this->ais_context->Erase(cur_shape, Standard_False); //AIS_InteractiveContext::Erase()

I noticed that erasing shapes DOES work if Iretrieve already displayed objects via AIS_InteractiveContext::DisplayedObjects()
so i thought maybe i could compare the AIS_InteractiveObject, which i get from DisplayedObjects(), to the TopoDS_Shape.
i came up with this

AIS_ListOfInteractive object_list;
AIS_ListIteratorOfListOfInteractive list_iterator;

//...iterate through the list

this->ais_context->Erase(cur_shape, Standard_False);

but Erase() will never be called because isSame always returns false.

what can i do? Any suggestions/mistakes in my code?

JuryS's picture

I'm use next for show or hide objects:

void DocumentCommon::UpdateFilter()
const TDF_Label &LabSat = myOCAFDoc->Main();
Handle_TPrsStd_AISPresentation prs;
Handle_TDataStd_Integer CurInt;

for (TDF_ChildIterator it(LabSat); it.More(); it.Next())
if (!it.Value().FindAttribute(TPrsStd_AISPresentation::GetID(),prs)) continue;

const TDF_Label &level0 = it.Value().FindChild(0,false);
if (level0.IsNull()) continue;

if (!level0.FindChild(20).FindAttribute(TDataStd_Integer::GetID(),CurInt)) continue;
const int FilterValue = CurInt->Get();
if (FilterValue<1 || FilterValue>21) continue;
if ( == false)

After objects that contains need filter displayed or hided and it's working cool with any version of OCC.