MCPcopy Create free account
hub / github.com/MITK/MITK / UndoLastInteraction

Method UndoLastInteraction

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:387–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385}
386
387void 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
444bool mitk::nnInteractiveTool::CanUndo() const

Callers 1

OnUndoButtonClickedMethod · 0.80

Calls 10

IsSessionRunningMethod · 0.95
CanUndoMethod · 0.95
HandleSessionErrorMethod · 0.95
DescriptionFunction · 0.85
ClearLastInteractionMethod · 0.80
atMethod · 0.80
UpdatePreviewMethod · 0.80
UndoMethod · 0.45
RemoveLastInteractionMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected