For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

XCAFDoc_ColorTool, how to apply color?

Alena's picture
Forums: 

Hello!
I didn't find complete sample on XDE, and I guess I'm doing something wrong.
I build the compound, name it using ShapeTool::AddShape. Result label is correct - I can find in it any selected shape of compound. I want to change color of subshape (e.g. edge), but usage of method ColorTool::SetColor has no effect on existing visualization. Here is my code:
//Initialization
TPrsStd_AISViewer::New(myData->Root(),myViewer);
Handle(AIS_InteractiveContext) CTX;
TPrsStd_AISViewer::Find(myData->Root(), CTX);
CTX->SetDisplayMode(AIS_Shaded);
myAISContext=CTX;
myAssembly = XCAFDoc_DocumentTool::ShapeTool (myData->Root());
myColors = XCAFDoc_DocumentTool::ColorTool(myData->Root());
//compound building
BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
//... add some shapes to compound
//name it
TDF_Label L = myAssembly->AddShape(Comp, 1);
//display it
Handle_XCAFPrs_AISObject actObject = new XCAFPrs_AISObject(L);
myAISContext->Display(actObject,Standard_False);
//... see the image and select one edge
//try to change color of selected edge
myAISContext->InitSelected();
if (myAISContext->HasSelectedShape()) {
TopoDS_Shape ts = myAISContext->SelectedShape();
//get the label of selected shape (is there more simple way to do it?)
TDF_Label aLabel = myAssembly->FindShape(ts); //this label is correct
Quantity_Color col (Quantity_NameOfColor::Quantity_NOC_YELLOW);
myColors->SetColor (aLabel, col, XCAFDoc_ColorGen); //I also tried XCAFDoc_ColorCurv
TPrsStd_AISViewer::Update(myData->Root()); //I'm not sure if this line is needed
}
RedrawView();
UpdateView();

I also tried to change color of the whole compound using it's label, but this doesn't work too. Where I wrong?
Thanks for any help!

Alena's picture

I think, I understood. Redisplay call was needed for to recompute AIS object. If I add this
myAISContext->Redisplay (myAISContext->SelectedInteractive());
it works.
But now I should explore, how I can call Redisplay, when I has no AIS object, but only label.
I share, if I'll do it.