diff --git a/src/stateManagement/imageIdSpecificStateManager.js b/src/stateManagement/imageIdSpecificStateManager.js index 168908d6c6..87675796b6 100755 --- a/src/stateManagement/imageIdSpecificStateManager.js +++ b/src/stateManagement/imageIdSpecificStateManager.js @@ -94,6 +94,27 @@ function newImageIdSpecificToolStateManager() { return imageIdToolState[toolName]; } + function replaceElementToolState(element, toolName, data) { + const enabledElement = external.cornerstone.getEnabledElement(element); + + if (!enabledElement.image) { + return; + } + replaceImageIdToolState(enabledElement.image.imageId, toolName, data); + } + + function replaceImageIdToolState(imageId, toolName, data) { + // If we don't have any tool state for this imageId, add an empty object + if (toolState.hasOwnProperty(imageId) === false) { + toolState[imageId] = {}; + } + + const imageIdToolState = toolState[imageId]; + + // Finally, add this new tool to the state + imageIdToolState[toolName] = data; + } + // Clears all tool data from this toolStateManager. function clearElementToolState(element) { const enabledElement = external.cornerstone.getEnabledElement(element); @@ -115,9 +136,12 @@ function newImageIdSpecificToolStateManager() { return { get: getElementToolState, add: addElementToolState, + replace: replaceImageIdToolState, clear: clearElementToolState, getImageIdToolState, addImageIdToolState, + replaceElementToolState, + replaceImageIdToolState, clearImageIdToolState, saveImageIdToolState, restoreImageIdToolState,