Skip to content

Commit

Permalink
Merge branch 'master' into fix-freehand-cornerstonejs#774
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesAPetts authored Mar 6, 2019
2 parents b078f07 + 1b4d373 commit f6d674a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples-old/freehand/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,12 @@ <h1>Freehand Sculpter Mouse Tool API</h1>
}
});

element.addEventListener('keydown', event => {
if (event.keyCode === 27) {
freehandTool.cancelDrawing(element);
}
});

</script>

</html>
36 changes: 36 additions & 0 deletions src/tools/annotation/FreehandMouseTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BaseAnnotationTool from './../base/BaseAnnotationTool.js';
import {
addToolState,
getToolState,
removeToolState,
} from './../../stateManagement/toolState.js';
import toolStyle from './../../stateManagement/toolStyle.js';
import toolColors from './../../stateManagement/toolColors.js';
Expand Down Expand Up @@ -1463,6 +1464,41 @@ export default class FreehandMouseTool extends BaseAnnotationTool {
this.configuration.invalidColor = value;
external.cornerstone.updateImage(this.element);
}

/**
* Ends the active drawing loop and removes the polygon.
*
* @public
* @param {Object} element - The element on which the roi is being drawn.
* @returns {undefined}
*/
cancelDrawing(element) {
if (!this._drawing) {
return;
}
const toolState = getToolState(element, this.name);

const config = this.configuration;

const data = toolState.data[config.currentTool];

data.active = false;
data.highlight = false;
data.handles.invalidHandlePlacement = false;

// Reset the current handle
config.currentHandle = 0;
config.currentTool = -1;
data.canComplete = false;

removeToolState(element, this.name, data);

this._drawing = false;
state.isMultiPartToolActive = false;
this._deactivateDraw(element);

external.cornerstone.updateImage(element);
}
}

function defaultFreehandConfiguration() {
Expand Down

0 comments on commit f6d674a

Please sign in to comment.