| 385 | } |
| 386 | |
| 387 | void mitk::nnInteractiveTool::UndoLastInteraction() |
| 388 | { |
| 389 | if (!this->IsSessionRunning() || !this->CanUndo()) |
| 390 | return; |
| 391 | |
| 392 | bool undone = false; |
| 393 | |
| 394 | try |
| 395 | { |
| 396 | undone = m_Impl->Undo(); |
| 397 | } |
| 398 | catch (const Exception& e) |
| 399 | { |
| 400 | // A remote session can fail here (lease expired, server gone, or at |
| 401 | // capacity). Tear it down and notify the GUI; otherwise propagate as the |
| 402 | // other session operations do. |
| 403 | if (this->HandleSessionError(Description(e))) |
| 404 | return; |
| 405 | |
| 406 | throw; |
| 407 | } |
| 408 | |
| 409 | if (!undone) |
| 410 | { |
| 411 | // The session reports nothing to undo; resync our record and stop. |
| 412 | m_Impl->ClearLastInteraction(); |
| 413 | return; |
| 414 | } |
| 415 | |
| 416 | // Remove the visualization of the undone interaction. The recorded prompt |
| 417 | // type is the one used at interaction time, which is not necessarily the |
| 418 | // currently active prompt type. |
| 419 | if (m_Impl->LastInteractionType.has_value()) |
| 420 | { |
| 421 | m_Impl->Interactors.at(m_Impl->LastInteractionType.value()) |
| 422 | ->RemoveLastInteraction(m_Impl->LastInteractionPromptType.value()); |
| 423 | } |
| 424 | else if (m_Impl->LastInteractionWasMask) |
| 425 | { |
| 426 | m_Impl->InitialSeg = nullptr; |
| 427 | } |
| 428 | |
| 429 | m_Impl->ClearLastInteraction(); |
| 430 | |
| 431 | // session.undo() restored the target buffer in place; repaint the preview |
| 432 | // from it via the regular update path (see the UndoRefreshPending branch in |
| 433 | // DoUpdatePreview). |
| 434 | m_Impl->UndoRefreshPending = true; |
| 435 | this->UpdatePreview(); |
| 436 | |
| 437 | // UpdatePreview() is synchronous, so the one-shot refresh has happened by |
| 438 | // now. Clear the flag defensively: if UpdatePreview() returned before |
| 439 | // reaching DoUpdatePreview (no input or preview image), a stale true would |
| 440 | // make the next interaction take the refresh branch and be dropped silently. |
| 441 | m_Impl->UndoRefreshPending = false; |
| 442 | } |
| 443 | |
| 444 | bool mitk::nnInteractiveTool::CanUndo() const |
no test coverage detected