I am using OPENCASCADE 3D library together with Qt. I have set up 3D display, and displayed several items of TopoDS_Shape in a window, using calls to AIS_InteractiveContext::Display method. Now I'd like to have some event processing when user picks a shape on 3D display.
I have checked documentation to AIS_InteractiveContext ( https://dev.opencascade.org/doc/refman/html/class_a_i_s___interactive_context.html ). There is a way to query items in 3D view. But it can only QUERY the selection:
- SelectedShape method (https://dev.opencascade.org/doc/refman/html/class_a_i_s___interactive_context.html#ac7879e85fade79a71e4f543a154763ff)
- IsSelected method for graphical representation
- Selection method
Constantly querying AIS_Interactive context for selection changes is not a way.
Is there any way to setup callback in opencascade when selection was changed?
CodePudding user response:
No, you should react on mouse clicks or key strokes to check whether the user wants to select something.
There is an Open CASCADE Qt sample called "Tutorial", you might want to check it. In the file ".../samples/qt/Common/src/View.cxx" you can find a sample implementation.
CodePudding user response:
I have found something related to this question:
https://dev.opencascade.org/content/how-receive-notification-selection-change
Tides of Internet may wash away that page, so I put it here too:
It is exactly what I mean. For example, when user clicks, you need to take current cursor position and pass it to OCCT context as follows:
occtContext->MoveTo(cursorX, cursorY, occtView);
occtContext->Select();
Or like this:
occtContext->Select(cursorX, cursorY, endpointX, endpointY, occtView);
And then you can get selected objects:
for (occtContext->InitSelected(); occtContext->MoreSelected(); occtContext->NextSelected())
{
Handle(AIS_InteractiveObject) selected = occtContext->SelectedInteractive();
}
And now you can call your callback function if there are selected objects
Such design does not look fine, but... I don't find anything else