but when I hit the widget handles (see red arrow):
my code is not executed at all … obviously I don’t understand why … can you tell me how to solve this task ? I have worked hard for this task and I didn’t succeeded by now …
Hello, try posting more of your code. Surely there is some if() there to explain why the TRACE() macro does not work when clicking the distance widget.
is working any time when I didn’t clicked on widget handles. When I clicked on widget handles, that code (vtkInteractorStyleImageEx::OnLeftButtonDown)is not executed at all. And my task is to select that widget in order to change his color, or, to delete it.
So, the issue is: why that code is not executed at click on widget handles ?
void CVTKDoc::CreateDistanceWidget(CVTKView* pView)
{
vtkDistanceWidget* pDistanceWidget = vtkDistanceWidget::New();
pDistanceWidget->SetInteractor(pView->m_pInteractor);
// Create the default widget representation and set the label format
pDistanceWidget->CreateDefaultRepresentation();
static_cast<vtkDistanceRepresentation*>(pDistanceWidget->GetRepresentation())->SetLabelFormat(_T("%-#6.3g mm"));
// Allow the observer to access the widget
vtkCallbackCommand* pKeypressCallback = vtkCallbackCommand::New();
pKeypressCallback->SetCallback(&CVTKDoc::KeypressCallbackFunction);
pKeypressCallback->SetClientData(pDistanceWidget);
pDistanceWidget->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, pKeypressCallback);
pDistanceWidget->On();
// Add widget pointer to map to cleanup later
if (NULL != pDistanceWidget)
InsertWidgetToMap(pView, pDistanceWidget);
pKeypressCallback->Delete();
}
and I see every keyboard key pressed. In order to select a widget (to modify it or delete it) I change the event, from vtkCommand::KeyPressEvent to vtkCommand::LeftButtonPressEvent. Every time when I press the left button, I see the TRACE, but when I press the button on the widget handle, the callback function is not executed at all, just like in the first solution
I see, friend. But I think you’re beeing a bit over-precise on this. If I were your user, the last place I’d click on to delete the ruler widget would be its handles. I’d just click anywhere else and hit DEL. The widget handles are meant to adjust it, thus, your callback being not triggered is the expected behavior.
Good observation. Thank you. I wonder if I could know if user press on widget body and not on 2d image, because the widget is spread over this 2d image …
The bug has been closed because is not a bug. It only need to catch accurate the line of the widget.
Thank you a lot Paulo !!!
P.S. Because I picked in my mouse pointer the vtkDistanceRepresentation2D object, I have to see now how can I get the vtkDistanceWidget pointer which contain this picked vtkDistanceRepresentation2D.
Well, if it is not a bug, then you have to carefully review your code as the callback is surelly being triggered by a click on the widget. I can’t see why this is wrong. Just click anywhere in the line to select it, just that. I don’t know why you insist in trying to select it by it’s tiny resizing handles located in the very ends of the widget… Like I said before: the last place I would click to select a widget would be by its resizing handles.