Identify the object

Hi I am creating an application which uses mouse extensively.

Is there any way to find which object(eg:- bspline curve,line,vertex etc...) is clicked or have focus in Open Cascade ??? so that I can attach specific behavior to that object .

I will highly appreciate any help in this.

Awaiting reply.

Regards,
...

suresh's picture

You should call MoveTo() function to highlight an object at a mouse location and then
you can get the detected objects using DetectedInteractive() function.

//On Mouse move

pContext->MoveTo(x, y, pView);
if(m_hContext->HasDetected())
{
m_hContext->InitDetected();

do
{
Handle_AIS_InteractiveObject hObj = m_hContext->DetectedInteractive();
if(!hObj.IsNull())
{
//Access the highlighted object
}
}
while(m_hContext->MoreDetected());
}

simple1238's picture

Hi suresh,

Thanks for your reply ;)

I am newbie to Opencascade and have good experience in Qt-4.2 .It's a request can you explain this snippet of code you have send.

suresh's picture

I guess, you have displayed vertices, edges(line, bspline) in the viewer using context
and you want to highlight the objects displayed on mouse move event and detect which object is highlighted at a moment.

AIS_InteractiveContext is class used to display/select objects in the viewer.

On the mouseMoveEvent() function of the view widget, call MoveTo() function of context with the mouse position (x, y) and the view object. This will highlight any object that is located at the screen location (x, y).

Then, call InitDetected(), DetectedInteractive() and MoreDetected() to know which object is highlighted. Once you got the handle to the object (AIS_InteractiveObject)highlighted, you can convert it to AIS_Shape if it is a AIS_Shape.

Handle_AIS_Shape hShape = Handle_AIS_Shape::DownCast(hObj);
if(!hShape.isNull()) //not AIS_Shape
{
return;
}

const TopoDS_Shape & shape = hShape->Shape(); //Get TopoDS_Shape (geometry)
if(shape.ShapeType()== TopAbs_VERTEX)
{
const TopoDS_Vertex & vertex = TopoDS::Vertex(shape);
}
else if(shape.ShapeType()== TopAbs_EDGE)
{
const TopoDS_Edge & edge = TopoDS::Edge(shape);
}

Now, you can access the edge or vertex that is highlighted.

Venugopal Gudimetla's picture

Hi Suresh,

On the side note, I have question..say you have detected a vertex when shape.ShapeType()== TopAbs_VERTEX or an Edge when shape.ShapeType()== TopAbs_EDGE, is there a way for me to get the underlying geometry of the object? how can i do that? pl excuse me that I am asking here, but I find this question quite related my own problem and just want some more information about the detected object.

Regards,
Venu

Peter Zbinden's picture

Hi suresh
Thank you for your post. It helps me very much.
For other visitors
// this additional line is needed, otherwise it loops forever
m_hContext->NextDetected());

while(m_hContext->MoreDetected());