Enabling child tools labeling and removing

This commit is contained in:
Bruno Alves de Faria 2017-12-11 16:21:39 -02:00
parent 4e31faa294
commit ebcdf80d49
8 changed files with 117 additions and 33 deletions

View File

@ -274,7 +274,8 @@ const setActiveToolAndSidebar = () => {
// Found a measurement, save tool and stop loop // Found a measurement, save tool and stop loop
if (measurement) { if (measurement) {
activeTool = cornerstoneToolType; const isArray = Array.isArray(cornerstoneToolType);
activeTool = isArray ? cornerstoneToolType[0] : cornerstoneToolType;
return false; return false;
} }

View File

@ -1,5 +1,4 @@
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
import { Viewerbase } from 'meteor/ohif:viewerbase'; import { Viewerbase } from 'meteor/ohif:viewerbase';
@ -47,6 +46,8 @@ Template.measurementTableHeaderRow.helpers({
Template.measurementTableHeaderRow.events({ Template.measurementTableHeaderRow.events({
'click .js-setTool'(event, instance) { 'click .js-setTool'(event, instance) {
const { toolGroup } = instance.data; 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);
} }
}); });

View File

@ -111,7 +111,7 @@
.timepointData .timepointData
display: flex display: flex
height: 27px min-height: 27px
margin-top: 1px margin-top: 1px
div div
@ -120,4 +120,4 @@
font-weight: 400 font-weight: 400
justify-content: space-around justify-content: space-around
line-height: 18px line-height: 18px
padding-bottom: 10px padding-bottom: 4px

View File

@ -2,7 +2,6 @@
.measurementTableTimepointCell .measurementTableTimepointCell
theme('border-left', '%s solid $uiBorderColor' % $uiBorderThickness) theme('border-left', '%s solid $uiBorderColor' % $uiBorderThickness)
theme('color', '$textPrimaryColor')
cursor: pointer cursor: pointer
padding: 0 10px padding: 0 10px
position: relative position: relative
@ -14,8 +13,14 @@
right: 5px right: 5px
top: 3px top: 3px
span
display: block
&.loading .loading-spinner &.loading .loading-spinner
display: block display: block
&:hover &, span
theme('color', '$textPrimaryColor')
&:hover, span:hover
theme('color', '$activeColor') theme('color', '$activeColor')

View File

@ -134,7 +134,10 @@ class MeasurementHandlers {
Collection._c2._simpleSchema.clean(measurement); Collection._c2._simpleSchema.clean(measurement);
// Update the measurement in the collection // 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 // Update the measurementData ID and measurementNumber
measurementData._id = parentMeasurement._id; measurementData._id = parentMeasurement._id;
@ -172,17 +175,8 @@ class MeasurementHandlers {
} }
static onAdded(event, instance, eventData) { static onAdded(event, instance, eventData) {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const { toolType } = eventData; const { toolType } = eventData;
const toolGroupId = toolsGroupsMap[toolType]; const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType);
const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId });
if (!toolGroup) return;
const tool = _.findWhere(toolGroup.childTools, { id: toolType });
const params = { const params = {
instance, instance,
eventData, eventData,
@ -191,6 +185,8 @@ class MeasurementHandlers {
toolGroup toolGroup
}; };
if (!tool) return;
if (tool.parentTool) { if (tool.parentTool) {
MeasurementHandlers.handleChildMeasurementAdded(params); MeasurementHandlers.handleChildMeasurementAdded(params);
} else { } else {
@ -275,17 +271,8 @@ class MeasurementHandlers {
} }
static onModified(event, instance, eventData) { static onModified(event, instance, eventData) {
const { MeasurementApi } = OHIF.measurements;
const configuration = MeasurementApi.getConfiguration();
const toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
const { toolType } = eventData; const { toolType } = eventData;
const toolGroupId = toolsGroupsMap[toolType]; const { toolGroupId, toolGroup, tool } = OHIF.measurements.getToolConfiguration(toolType);
const toolGroup = _.findWhere(configuration.measurementTools, { id: toolGroupId });
if (!toolGroup) return;
const tool = _.findWhere(toolGroup.childTools, { id: toolType });
const params = { const params = {
instance, instance,
eventData, eventData,
@ -294,6 +281,8 @@ class MeasurementHandlers {
toolGroup toolGroup
}; };
if (!tool) return;
if (tool.parentTool) { if (tool.parentTool) {
MeasurementHandlers.handleChildMeasurementModified(params); MeasurementHandlers.handleChildMeasurementModified(params);
} else { } else {
@ -301,16 +290,14 @@ class MeasurementHandlers {
} }
} }
static onRemoved(e, instance, eventData) { static handleSingleMeasurementRemoved({ instance, eventData, tool, toolGroupId, toolGroup }) {
OHIF.log.info('CornerstoneToolsMeasurementRemoved'); OHIF.log.info('CornerstoneToolsMeasurementRemoved');
const measurementData = eventData.measurementData; const measurementData = eventData.measurementData;
const { measurementApi, timepointApi } = instance.data; const { measurementApi, timepointApi } = instance.data;
const Collection = measurementApi.tools[eventData.toolType]; const Collection = measurementApi.tools[eventData.toolType];
// Stop here if the tool data shall not be persisted (e.g. temp tools) // Stop here if the tool data shall not be persisted (e.g. temp tools)
if (!Collection) { if (!Collection) return;
return;
}
const measurementTypeId = measurementApi.toolsGroupsMap[measurementData.toolType]; const measurementTypeId = measurementApi.toolsGroupsMap[measurementData.toolType];
const measurement = Collection.findOne(measurementData._id); const measurement = Collection.findOne(measurementData._id);
@ -335,6 +322,62 @@ class MeasurementHandlers {
// Signal unsaved changes // Signal unsaved changes
OHIF.ui.unsavedChanges.set('viewer.studyViewer.measurements.' + eventData.toolType); 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; OHIF.measurements.MeasurementHandlers = MeasurementHandlers;

View File

@ -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
};
};

View File

@ -8,6 +8,7 @@ import './getImageDataUrl';
import './getMeasurementsGroupedByNumber'; import './getMeasurementsGroupedByNumber';
import './getLocationLabel'; import './getLocationLabel';
import './getTimepointName'; import './getTimepointName';
import './getToolConfiguration';
import './hangingProtocolCustomizations'; import './hangingProtocolCustomizations';
import './MeasurementHandlers'; import './MeasurementHandlers';
import './MeasurementManager'; import './MeasurementManager';

View File

@ -4,7 +4,13 @@ import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
OHIF.measurements.toggleLabelButton = options => { 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; const measurementId = options.measurement._id;
let buttonView = null; let buttonView = null;