Color/Transp./Material for selected InteractiveObjects in AIS_InteractiveContext using XCAF

Hello folks

I currently encounter the following problem:
For all selected shapes in my AIS_InteractiveContext I want to set e.g. the color, material, transparancy, shade mode... . Before using XCAF everything was just fine by using e.g.:

for (theContext->InitCurrent(); theContext->MoreCurrent(); theContext->NextCurrent() )
{
theContext->SetDisplayMode(theContext->Current(), 1, Standard_False);
}

After I introduced XCAF this procedure still works for the display mode but not for the transparency/material/color setting. So I thought I have to use the TPrsStd_AISPresentation functions to assign these attributes to the displayed shapes. The problem is that I can\'t get the TPrsStd_AISPresentation from any selected AIS_InteractiveObject

I tried:
Handle(AIS_InteractiveContext) theContext = ...
theContext->InitCurrent();
for( theContext->InitCurrent(); theContext->MoreCurrent(); theContext->NextSelected() )
{
Handle(TPrsStd_AISPresentation) curPres = Handle(TPrsStd_AISPresentation::DownCast(theContext->Current()));
if(!curPres.IsNull())
{
curPres->SetMaterial(theNOM);
curPres->Update();
}
}

Did I oversee some important details? How can I assign the user selected attributes to the selected displayed shapes? In the following I assign the shapes in the TDocStd_Document to AISViewer.

for(Standard_Integer cnt=1; cnt {
TDF_Label theLab = myLabelSequence.Value(cnt);
Handle(TPrsStd_AISPresentation) TPrsPresentation;

TPrsPresentation = TPrsStd_AISPresentation::Set(theLab, XCAFPrs_Driver::GetID());

if(!TPrsPresentation->HasOwnMaterial())
TPrsPresentation->SetMaterial(Graphic3d_NOM_DEFAULT);

TPrsPresentation->SetMode(1);
TPrsPresentation->Display(Standard_True);
}

Thanks for any hint and/or help.

D.

Dennis G.'s picture

I was wrong. The DownCast is not the problem.
So I retrieve the AISPresentation and I can assign the new 'material name' but the program crashes on a 'segmentation fault' when calling 'Update()'.

It makes no sense to me, because after translation of the STEP data I use exactly the same AISPresentation (identical label) to assign the programs default material if no material has been defined in the STEP file (and it works!).

Has anyone any idea?

Thanks,

D.