【cornerstone】撤销标注点位(通过ctrl+z)
注意:只能撤销第一个点之后的点位,无法撤销第一个点。
函数主体部分:
cancelPoint(event){
// 第一个点是无法撤销的
let that = this;
if (event.ctrlKey && event.code === 'KeyZ') {
var enableElement = that.img_show_element;
var toolName = "FreehandRoi";
console.log('ctrl+z');
try {
const tool = cornerstoneTools.getToolForElement(enableElement, toolName);
const activeDrawing = (tool || {})._activeDrawingToolReference;
// console.log('activeDrawing', activeDrawing);
if (
activeDrawing &&
activeDrawing.handles &&
(activeDrawing.handles.points || []).length > 1
) {
const configuration = tool._configuration;
if (configuration.currentHandle > 1) {
const len = activeDrawing.handles.points.length;
activeDrawing.handles.points.length = len - 1;
activeDrawing.handles.points[len - 2].lines = [];
configuration.currentHandle = configuration.currentHandle - 1;
cornerstone.updateImage(enableElement);
}
}
} catch (error) {
console.log(error);
}
}
},
vue
通过在mounted
中添加document.addEventListener('keyup', this.cancelPoint);
来调用。