Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
activate_tool: function () {
var tool_name = this.model.get('_selected_tool');
console.log('switching to tool: ' + tool_name);
if (tool_name == 'reset') {
this._disable_all_tools(this.viewer);
cs.reset(this.viewer);
var toolStateManager = ctools.getElementToolStateManager(this.viewer);
// Note that this only works on ImageId-specific tool state managers (for now)
toolStateManager.clear(this.viewer);
cs.updateImage(this.viewer);
this.model.set('_tool_state_in', '');
this.model.set('_tool_state_out', '');
this._setup_tools();
} else {
this._disable_all_tools(this.viewer);
if (tool_name == 'zoom') {
ctools.zoom.activate(this.viewer, 1);
}
if (tool_name == 'window') {
ctools.wwwc.activate(this.viewer, 1);
}
if (tool_name == 'pan') {
ctools.pan.activate(this.viewer, 1);
ctools.zoom.activate(this.viewer, 2);
}
if (tool_name == 'bbox') {
addNewMeasurement(evt: any) {
const eventData = evt.detail
const { element, image } = eventData
const measurementData: any = this.createNewMeasurement(eventData)
cornerstoneTools.addToolState(element, this.name, measurementData)
const { end } = measurementData.handles
cornerstone.updateImage(element)
moveNewHandle(
eventData,
this.name,
measurementData,
end,
{},
'mouse',
() => {
if (anyHandlesOutsideImage(eventData, measurementData.handles)) {
// Delete the measurement
cornerstoneTools.removeToolState(element, this.name, measurementData)
} else {
const center = getCenter(measurementData.handles)
measurementData.handles.perpendicularPoint.x = center.x
const handleDoneMove = (handle: any) => {
data.invalidated = true
if (anyHandlesOutsideImage(eventData, data.handles)) {
// Delete the measurement
cornerstoneTools.removeToolState(element, this.name, data)
}
if (handle) {
handle.moving = false
handle.selected = true
}
setToolCursor(this.element, this.svgCursor)
cornerstone.updateImage(element)
element.addEventListener(EVENTS.MOUSE_MOVE, this.mouseMoveCallback)
element.addEventListener(EVENTS.TOUCH_START, this._moveCallback)
}
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
continue;
}
if (labelmap2D) {
labelmap2D.segmentsOnLabelmap.push(segmentIndex);
} else {
labelmap2D = getters.labelmap2DByImageIdIndex(
labelmap3D,
i,
rows,
columns
);
}
}
cornerstone.updateImage(element);
};
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
removeToolState: ({ element, toolType, tool }) => {
cornerstoneTools.removeToolState(element, toolType, tool);
cornerstone.updateImage(element);
},
};
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element);
});