Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(imageIdSpecificStateManager.js): Methods for managing toolState via imageId #1151

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions src/stateManagement/imageIdSpecificStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ function newImageIdSpecificToolStateManager() {

// Here we add tool state, this is done by tools as well
// As modules that restore saved state
function addImageIdSpecificToolState(element, toolType, data) {
function addElementToolState(element, toolType, data) {
const enabledElement = external.cornerstone.getEnabledElement(element);

// If we don't have an image for this element exit early
if (!enabledElement.image) {
return;
}
addImageIdToolState(enabledElement.image.imageId, toolType, data);
}

function addImageIdToolState(imageId, toolType, data) {
// If we don't have any tool state for this imageId, add an empty object
if (toolState.hasOwnProperty(enabledElement.image.imageId) === false) {
toolState[enabledElement.image.imageId] = {};
if (toolState.hasOwnProperty(imageId) === false) {
toolState[imageId] = {};
}

const imageIdToolState = toolState[enabledElement.image.imageId];
const imageIdToolState = toolState[imageId];

// If we don't have tool state for this type of tool, add an empty object
if (imageIdToolState.hasOwnProperty(toolType) === false) {
Expand All @@ -62,49 +65,60 @@ function newImageIdSpecificToolStateManager() {
toolData.data.push(data);
}

function getElementToolState(element, toolType) {
const enabledElement = external.cornerstone.getEnabledElement(element);

// If the element does not have an image return undefined.
if (!enabledElement.image) {
return;
}

return getImageIdToolState(enabledElement.image.imageId, toolType);
}

// Here you can get state - used by tools as well as modules
// That save state persistently
function getImageIdSpecificToolState(element, toolType) {
const enabledElement = external.cornerstone.getEnabledElement(element);
function getImageIdToolState(imageId, toolType) {
// If we don't have any tool state for this imageId, return undefined

if (
!enabledElement.image ||
toolState.hasOwnProperty(enabledElement.image.imageId) === false
) {
if (toolState.hasOwnProperty(imageId) === false) {
return;
}

const imageIdToolState = toolState[enabledElement.image.imageId];
const imageIdToolState = toolState[imageId];

// If we don't have tool state for this type of tool, return undefined
if (imageIdToolState.hasOwnProperty(toolType) === false) {
return;
}

const toolData = imageIdToolState[toolType];

return toolData;
return imageIdToolState[toolType];
}

// Clears all tool data from this toolStateManager.
function clearImageIdSpecificToolStateManager(element) {
function clearElementToolState(element) {
const enabledElement = external.cornerstone.getEnabledElement(element);

if (
!enabledElement.image ||
toolState.hasOwnProperty(enabledElement.image.imageId) === false
) {
if (!enabledElement.image) {
return;
}
clearImageIdToolState(enabledElement.imageId);
}
Comment on lines +98 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was an error, missing the "image" object

clearImageIdToolState(enabledElement.imageId);

to change:

clearImageIdToolState(enabledElement.image.imageId);


function clearImageIdToolState(imageId) {
if (toolState.hasOwnProperty(imageId) === false) {
return;
}

delete toolState[enabledElement.image.imageId];
delete toolState[imageId];
}

return {
get: getImageIdSpecificToolState,
add: addImageIdSpecificToolState,
clear: clearImageIdSpecificToolStateManager,
get: getElementToolState,
add: addElementToolState,
clear: clearElementToolState,
getImageIdToolState,
addImageIdToolState,
clearImageIdToolState,
saveImageIdToolState,
restoreImageIdToolState,
saveToolState,
Expand Down