Problem in setting color

i m new to opencascade.
i have to setcolor to the 3d view..

i gave the below code to setcolor, it does not works and showing protected memory used violation:
(myAISContext is the object of AIS_InteractiveContext)
myAISContext->SetDisplayMode(ais,1);
myAISContext->SetColor(ais ,Quantity_NOC_BLACK,Standard_True);
myAISContext->Display(ais,Standard_True);

I am actually having an option to change the color of the 3d view. how to do that?
Please help me

deepasundarip's picture

Handle(AIS_Shape) ais = new AIS_Shape(myAISContext->SelectedShape());

Tilman Leune's picture

Are you sure you have actually a selected shape?

You have to call myAISContext->InitSelected() and then iterat over the selected objects, like this:

for(myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
{
//do something with your selected object(s)
Handle(AIS_Shape) ais = myAISContext->SelectedInteractive();
myAISContext->SetDisplayMode(ais,1);
myAISContext->SetColor(ais ,Quantity_NOC_BLACK,Standard_True);
}
myAISContext->UpdateCurrentViewer();

the above code is untested in it's current form, but the selection mechanism is taken driectly from my project.

Tilman Leune's picture

ignore the -Tags