diff --git a/LesionTracker/client/components/viewer/viewer.js b/LesionTracker/client/components/viewer/viewer.js index fa95f17de..40ee9d892 100644 --- a/LesionTracker/client/components/viewer/viewer.js +++ b/LesionTracker/client/components/viewer/viewer.js @@ -274,7 +274,8 @@ const setActiveToolAndSidebar = () => { // Found a measurement, save tool and stop loop if (measurement) { - activeTool = cornerstoneToolType; + const isArray = Array.isArray(cornerstoneToolType); + activeTool = isArray ? cornerstoneToolType[0] : cornerstoneToolType; return false; } diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTableHeaderRow/measurementTableHeaderRow.js b/Packages/ohif-measurements/client/components/measurementTable/measurementTableHeaderRow/measurementTableHeaderRow.js index 7c1366be0..f20e0280f 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTableHeaderRow/measurementTableHeaderRow.js +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTableHeaderRow/measurementTableHeaderRow.js @@ -1,5 +1,4 @@ import { Template } from 'meteor/templating'; -import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; import { Viewerbase } from 'meteor/ohif:viewerbase'; @@ -47,6 +46,8 @@ Template.measurementTableHeaderRow.helpers({ Template.measurementTableHeaderRow.events({ 'click .js-setTool'(event, instance) { const { toolGroup } = instance.data; - Viewerbase.toolManager.setActiveTool(toolGroup.childTools[0].cornerstoneToolType); + const toolType = toolGroup.childTools[0].cornerstoneToolType; + const activeToolId = Array.isArray(toolType) ? toolType[0] : toolType; + Viewerbase.toolManager.setActiveTool(activeToolId); } }); diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.styl b/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.styl index ea300c25a..352a39d92 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.styl +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTableRow/measurementTableRow.styl @@ -111,7 +111,7 @@ .timepointData display: flex - height: 27px + min-height: 27px margin-top: 1px div @@ -120,4 +120,4 @@ font-weight: 400 justify-content: space-around line-height: 18px - padding-bottom: 10px + padding-bottom: 4px diff --git a/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.styl b/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.styl index b4da3b3e1..e0467a5f5 100644 --- a/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.styl +++ b/Packages/ohif-measurements/client/components/measurementTable/measurementTableTimepointCell/measurementTableTimepointCell.styl @@ -2,7 +2,6 @@ .measurementTableTimepointCell theme('border-left', '%s solid $uiBorderColor' % $uiBorderThickness) - theme('color', '$textPrimaryColor') cursor: pointer padding: 0 10px position: relative @@ -14,8 +13,14 @@ right: 5px top: 3px + span + display: block + &.loading .loading-spinner display: block - &:hover + &, span + theme('color', '$textPrimaryColor') + + &:hover, span:hover theme('color', '$activeColor') diff --git a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js index b0ff7cd85..4354d4c55 100644 --- a/Packages/ohif-measurements/client/lib/MeasurementHandlers.js +++ b/Packages/ohif-measurements/client/lib/MeasurementHandlers.js @@ -134,7 +134,10 @@ class MeasurementHandlers { Collection._c2._simpleSchema.clean(measurement); // Update the measurement in the collection - Collection.update(parentMeasurement._id, { $set: { [key]: measurement[key] } }); + Collection.update(parentMeasurement._id, { + $set: { [key]: measurement[key] }, + $inc: { childToolsCount: 1 } + }); // Update the measurementData ID and measurementNumber measurementData._id = parentMeasurement._id; @@ -172,17 +175,8 @@ class MeasurementHandlers { } static onAdded(event, instance, eventData) { - const { MeasurementApi } = OHIF.measurements; - const configuration = MeasurementApi.getConfiguration(); - const toolsGroupsMap = MeasurementApi.getToolsGroupsMap(); - const { toolType } = eventData; - const toolGroupId = toolsGroupsMap[toolType]; - const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId }); - - if (!toolGroup) return; - - const tool = _.findWhere(toolGroup.childTools, { id: toolType }); + const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType); const params = { instance, eventData, @@ -191,6 +185,8 @@ class MeasurementHandlers { toolGroup }; + if (!tool) return; + if (tool.parentTool) { MeasurementHandlers.handleChildMeasurementAdded(params); } else { @@ -275,17 +271,8 @@ class MeasurementHandlers { } static onModified(event, instance, eventData) { - const { MeasurementApi } = OHIF.measurements; - const configuration = MeasurementApi.getConfiguration(); - const toolsGroupsMap = MeasurementApi.getToolsGroupsMap(); - const { toolType } = eventData; - const toolGroupId = toolsGroupsMap[toolType]; - const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId }); - - if (!toolGroup) return; - - const tool = _.findWhere(toolGroup.childTools, { id: toolType }); + const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType); const params = { instance, eventData, @@ -294,6 +281,8 @@ class MeasurementHandlers { toolGroup }; + if (!tool) return; + if (tool.parentTool) { MeasurementHandlers.handleChildMeasurementModified(params); } else { @@ -301,16 +290,14 @@ class MeasurementHandlers { } } - static onRemoved(e, instance, eventData) { + static handleSingleMeasurementRemoved({ instance, eventData, tool, toolGroupId, toolGroup }) { OHIF.log.info('CornerstoneToolsMeasurementRemoved'); const measurementData = eventData.measurementData; const { measurementApi, timepointApi } = instance.data; const Collection = measurementApi.tools[eventData.toolType]; // Stop here if the tool data shall not be persisted (e.g. temp tools) - if (!Collection) { - return; - } + if (!Collection) return; const measurementTypeId = measurementApi.toolsGroupsMap[measurementData.toolType]; const measurement = Collection.findOne(measurementData._id); @@ -335,6 +322,62 @@ class MeasurementHandlers { // Signal unsaved changes OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); } + + static handleChildMeasurementRemoved({ instance, eventData, tool, toolGroupId, toolGroup }) { + OHIF.log.info('CornerstoneToolsMeasurementRemoved'); + const measurementData = eventData.measurementData; + const { measurementApi, timepointApi } = instance.data; + const Collection = measurementApi.tools[tool.parentTool]; + + // Stop here if the tool data shall not be persisted (e.g. temp tools) + if (!Collection) return; + + const measurement = Collection.findOne(measurementData._id); + + // Stop here if the measurement is already gone or never existed + if (!measurement) return; + + if (measurement.childToolsCount === 1) { + // Remove the measurement + Collection.remove(measurement._id); + + // Sync the new measurement data with cornerstone tools + const baseline = timepointApi.baseline(); + measurementApi.sortMeasurements(baseline.timepointId); + } else { + // Update the measurement in the collection + Collection.update(measurement._id, { + $set: { [tool.attribute]: null }, + $inc: { childToolsCount: -1 } + }); + } + + // Repaint the images on all viewports without the removed measurements + _.each($('.imageViewerViewport'), element => cornerstone.updateImage(element)); + + // Signal unsaved changes + OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); + } + + static onRemoved(e, instance, eventData) { + const { toolType } = eventData; + const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType); + const params = { + instance, + eventData, + tool, + toolGroupId, + toolGroup + }; + + if (!tool) return; + + if (tool.parentTool) { + MeasurementHandlers.handleChildMeasurementRemoved(params); + } else { + MeasurementHandlers.handleSingleMeasurementRemoved(params); + } + } } OHIF.measurements.MeasurementHandlers = MeasurementHandlers; diff --git a/Packages/ohif-measurements/client/lib/getToolConfiguration.js b/Packages/ohif-measurements/client/lib/getToolConfiguration.js new file mode 100644 index 000000000..67e4810d4 --- /dev/null +++ b/Packages/ohif-measurements/client/lib/getToolConfiguration.js @@ -0,0 +1,27 @@ +import { _ } from 'meteor/underscore'; +import { OHIF } from 'meteor/ohif:core'; + +/** + * Return the tool configuration of a given tool type + * + * @param {String} toolType The tool type of the desired configuration + */ +OHIF.measurements.getToolConfiguration = toolType => { + const { MeasurementApi } = OHIF.measurements; + const configuration = MeasurementApi.getConfiguration(); + const toolsGroupsMap = MeasurementApi.getToolsGroupsMap(); + + const toolGroupId = toolsGroupsMap[toolType]; + const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId }); + + let tool; + if (toolGroup) { + tool = _.findWhere(toolGroup.childTools, { id: toolType }); + } + + return { + toolGroupId, + toolGroup, + tool + }; +}; diff --git a/Packages/ohif-measurements/client/lib/index.js b/Packages/ohif-measurements/client/lib/index.js index 7794058f5..0440fbac6 100644 --- a/Packages/ohif-measurements/client/lib/index.js +++ b/Packages/ohif-measurements/client/lib/index.js @@ -8,6 +8,7 @@ import './getImageDataUrl'; import './getMeasurementsGroupedByNumber'; import './getLocationLabel'; import './getTimepointName'; +import './getToolConfiguration'; import './hangingProtocolCustomizations'; import './MeasurementHandlers'; import './MeasurementManager'; diff --git a/Packages/ohif-measurements/client/lib/toggleLabelButton.js b/Packages/ohif-measurements/client/lib/toggleLabelButton.js index ac1104184..0acb51e2e 100644 --- a/Packages/ohif-measurements/client/lib/toggleLabelButton.js +++ b/Packages/ohif-measurements/client/lib/toggleLabelButton.js @@ -4,7 +4,13 @@ import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; OHIF.measurements.toggleLabelButton = options => { - const toolType = options.measurement.toolType; + let { toolType } = options.measurement; + const { tool } = OHIF.measurements.getToolConfiguration(toolType); + + if (!tool) return; + + toolType = (tool && tool.parentTool) || toolType; + const measurementId = options.measurement._id; let buttonView = null;