Enabling child tools labeling and removing
This commit is contained in:
parent
4e31faa294
commit
ebcdf80d49
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
};
|
||||
};
|
||||
@ -8,6 +8,7 @@ import './getImageDataUrl';
|
||||
import './getMeasurementsGroupedByNumber';
|
||||
import './getLocationLabel';
|
||||
import './getTimepointName';
|
||||
import './getToolConfiguration';
|
||||
import './hangingProtocolCustomizations';
|
||||
import './MeasurementHandlers';
|
||||
import './MeasurementManager';
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user