src/stateManagement/imageIdSpecificStateManager.js
/**
 * Implements an imageId specific tool state management strategy.  This means that
 * Measurements data is tied to a specific imageId and only visible for enabled elements
 * That are displaying that imageId.
 * @public
 * @constructor newImageIdSpecificToolStateManager
 * @memberof StateManagement
 *
 * @returns {Object} An imageIdSpecificToolStateManager instance.
 */
Implements an imageId specific tool state management strategy.  This means that
Measurements data is tied to a specific imageId and only visible for enabled elements
That are displaying that imageId.

@returns {Object} An imageIdSpecificToolStateManager instance.
Implements an imageId specific tool state management strategy . This means that Measurements data is tied to a specific imageId and only visible for enabled elements That are displaying that imageId . @returns { Object } An imageIdSpecificToolStateManager instance .
function newImageIdSpecificToolStateManager() {
  let toolState = {};
  function saveImageIdToolState(imageId) {
    return toolState[imageId];
  }
  function restoreImageIdToolState(imageId, imageIdToolState) {
    toolState[imageId] = imageIdToolState;
  }
  function saveToolState() {
    return toolState;
  }
  function restoreToolState(savedToolState) {
    toolState = savedToolState;
  }
  function addImageIdSpecificToolState(element, toolType, data) {
    const enabledElement = external.cornerstone.getEnabledElement(element);
    if (!enabledElement.image) {
      return;
    }
    if (toolState.hasOwnProperty(enabledElement.image.imageId) === false) {
      toolState[enabledElement.image.imageId] = {};
    }
    const imageIdToolState = toolState[enabledElement.image.imageId];
    if (imageIdToolState.hasOwnProperty(toolType) === false) {
      imageIdToolState[toolType] = {
        data: [],
      };
    }
    const toolData = imageIdToolState[toolType];
    toolData.data.push(data);
  }
  function getImageIdSpecificToolState(element, toolType) {
    const enabledElement = external.cornerstone.getEnabledElement(element);
    if (
      !enabledElement.image ||
      toolState.hasOwnProperty(enabledElement.image.imageId) === false
    ) {
      return;
    }
    const imageIdToolState = toolState[enabledElement.image.imageId];
    if (imageIdToolState.hasOwnProperty(toolType) === false) {
      return;
    }
    const toolData = imageIdToolState[toolType];
    return toolData;
  }
  function clearImageIdSpecificToolStateManager(element) {
    const enabledElement = external.cornerstone.getEnabledElement(element);
    if (
      !enabledElement.image ||
      toolState.hasOwnProperty(enabledElement.image.imageId) === false
    ) {
      return;
    }
    delete toolState[enabledElement.image.imageId];
  }
  return {
    get: getImageIdSpecificToolState,
    add: addImageIdSpecificToolState,
    clear: clearImageIdSpecificToolStateManager,
    saveImageIdToolState,
    restoreImageIdToolState,
    saveToolState,
    restoreToolState,
    toolState,
  };
}
function newImageIdSpecificToolStateManager ( ) { let toolState = { } ; function saveImageIdToolState ( imageId ) { return toolState [ imageId ] ; } function restoreImageIdToolState ( imageId , imageIdToolState ) { toolState [ imageId ] = imageIdToolState ; } function saveToolState ( ) { return toolState ; } function restoreToolState ( savedToolState ) { toolState = savedToolState ; } function addImageIdSpecificToolState ( element , toolType , data ) { const enabledElement = external . cornerstone . getEnabledElement ( element ) ; if ( ! enabledElement . image ) { return ; } if ( toolState . hasOwnProperty ( enabledElement . image . imageId ) === false ) { toolState [ enabledElement . image . imageId ] = { } ; } const imageIdToolState = toolState [ enabledElement . image . imageId ] ; if ( imageIdToolState . hasOwnProperty ( toolType ) === false ) { imageIdToolState [ toolType ] = { data : [ ] , } ; } const toolData = imageIdToolState [ toolType ] ; toolData . data . push ( data ) ; } function getImageIdSpecificToolState ( element , toolType ) { const enabledElement = external . cornerstone . getEnabledElement ( element ) ; if ( ! enabledElement . image || toolState . hasOwnProperty ( enabledElement . image . imageId ) === false ) { return ; } const imageIdToolState = toolState [ enabledElement . image . imageId ] ; if ( imageIdToolState . hasOwnProperty ( toolType ) === false ) { return ; } const toolData = imageIdToolState [ toolType ] ; return toolData ; } function clearImageIdSpecificToolStateManager ( element ) { const enabledElement = external . cornerstone . getEnabledElement ( element ) ; if ( ! enabledElement . image || toolState . hasOwnProperty ( enabledElement . image . imageId ) === false ) { return ; } delete toolState [ enabledElement . image . imageId ] ; } return { get : getImageIdSpecificToolState , add : addImageIdSpecificToolState , clear : clearImageIdSpecificToolStateManager , saveImageIdToolState , restoreImageIdToolState , saveToolState , restoreToolState , toolState , } ; }
Implements an imageId specific tool state management strategy.
Implements an imageId specific tool state management strategy .
// Here we add tool state, this is done by tools as well // As modules that restore saved state // Here we add tool state, this is done by tools as well // As modules that restore saved state // If we don't have an image for this element exit early // If we don't have any tool state for this imageId, add an empty object // If we don't have tool state for this type of tool, add an empty object // Finally, add this new tool to the state // Here you can get state - used by tools as well as modules // That save state persistently // If we don't have any tool state for this imageId, return undefined // If we don't have tool state for this type of tool, return undefined // Clears all tool data from this toolStateManager.