Skip to content

Commit

Permalink
feat(imageIdSpecificStateManager): add replace imageIdToolState fun…
Browse files Browse the repository at this point in the history
…ctions

There is currently no function to consume the same output from getImageIdToolState, which is the
state of a specific tool for the given imageId. addElementToolState requires a single item input,
and without replace, requires both a clear step and an iteration over all items to add into the
tool's id-specific state.
  • Loading branch information
mix3d committed Dec 16, 2020
1 parent 8a261a2 commit cd05ac4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/stateManagement/imageIdSpecificStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -115,9 +136,12 @@ function newImageIdSpecificToolStateManager() {
return {
get: getElementToolState,
add: addElementToolState,
replace: replaceImageIdToolState,
clear: clearElementToolState,
getImageIdToolState,
addImageIdToolState,
replaceElementToolState,
replaceImageIdToolState,
clearImageIdToolState,
saveImageIdToolState,
restoreImageIdToolState,
Expand Down

0 comments on commit cd05ac4

Please sign in to comment.