Find shape in view

hi

I'm newbie in OCCT

i have view and create some shape in it that listed in treeview .i want  when i clicked on treeview item, color of the related shape changes.

please help

 

Benjamin Bihler's picture

Hi Mohammad,

you can get the highlighted object like this

    Handle(AIS_InteractiveObject) newHighlightedObject;

    if (interactiveContext->HasDetected())
    {
        newHighlightedObject = interactiveContext->DetectedInteractive();
    }

or the selected object like this

if (0 != interactiveContext->NbSelected())
    {
        for (interactiveContext->InitSelected(); interactiveContext->MoreSelected();
                interactiveContext->NextSelected())
        {
            const Handle(AIS_InteractiveObject) object =
                    interactiveContext->SelectedInteractive();
            
            ...
        }
    }

Then you might want to check the owner of the selected object like this:

            if (object->HasOwner())
            {
                const Handle(Standard_Transient)& owner = object->GetOwner();

                if (owner.IsNull())
                {
                    // Do nothing! This is a temporary visualization element.
                }
                else if (owner->IsKind(STANDARD_TYPE(TPrsStd_AISPresentation)))
                {
                    Handle(TPrsStd_AISPresentation) presentation =
                            Handle(TPrsStd_AISPresentation)::DownCast(owner);

                    // Modify the presentation...
                    ...
                }
            }

But it might depend on your document handling what the owner is and what you want to do with it. I hope that this gives you an idea. The rest I guess you would have to find out by trying...

Benjamin