UNPKG

medsurf-draw

Version:

Draw annotations on jpg/zoomify images, based on PIXI.js

164 lines 7.7 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import * as MedsurfDraw from "../../public-api"; import { BaseGenerator, BaseGeneratorModel } from "../../bases/generators/BaseGenerator"; export var ArrowGeneratorStates; (function (ArrowGeneratorStates) { ArrowGeneratorStates[ArrowGeneratorStates["ARROW"] = 0] = "ARROW"; ArrowGeneratorStates[ArrowGeneratorStates["TEXT"] = 1] = "TEXT"; })(ArrowGeneratorStates || (ArrowGeneratorStates = {})); var ArrowGeneratorModel = (function (_super) { __extends(ArrowGeneratorModel, _super); function ArrowGeneratorModel() { return _super !== null && _super.apply(this, arguments) || this; } return ArrowGeneratorModel; }(BaseGeneratorModel)); export { ArrowGeneratorModel }; var ArrowGenerator = (function (_super) { __extends(ArrowGenerator, _super); function ArrowGenerator(model) { var _this = _super.call(this, model) || this; _this._state = ArrowGeneratorStates.ARROW; _this.target.modeInteraction.setModeItem("drawing"); _this._setupGenerator(); return _this; } ArrowGenerator.prototype.end = function () { if (this._arrowPrimitiveGenerator) { this._arrowPrimitiveGenerator.removeAllListeners(); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.removeAllListeners(); } _super.prototype.end.call(this); }; ArrowGenerator.prototype.destroy = function (options) { this.end(); if (this._lineElement && this._lineElement.modeInteraction.lastMode.endsWith('new')) { this._lineElement.modeInteraction.setMode('delete_draw'); } if (this._arrowPrimitiveGenerator) { this._arrowPrimitiveGenerator.destroy(); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.destroy(); } }; ArrowGenerator.prototype.endGenerator = function () { _super.prototype.endGenerator.call(this); this._startPositionPointElement.onButtonSetSelftest(true); this._startPositionPointElement.model.selftestItems = this.target.getImageObjects() .filter(function (imageObject) { return imageObject.modeInteraction.lastMode.startsWith('draw_select'); }) .map(function (imageObject) { return imageObject.name; }); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; ArrowGenerator.prototype.abortGenerator = function () { _super.prototype.abortGenerator.call(this); this.target.getImageObjects() .filter(function (imageObject) { return imageObject.modeInteraction.lastMode.startsWith('draw_') && imageObject.modeInteraction.lastMode.endsWith('_new'); }) .forEach(function (imageObject) { imageObject.modeInteraction.setMode("delete_draw"); }); this.target.sortChildren(); this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode); }; ArrowGenerator.prototype._setupGenerator = function (positionPoint) { if (this._state === ArrowGeneratorStates.ARROW) { this._arrowPrimitiveGenerator = new MedsurfDraw.ArrowPrimitiveGenerator({ target: this.target, layerGroup: this.data.layerGroup, image: this.data.image, stickMode: MedsurfDraw.StickMode.NOELEMENTS, startElement: positionPoint, hasWedgePoint: this.data.hasWedgePoint, rotateWithLine: true, withScaling: true, triggerImmediateEndDraw: true }); this._arrowPrimitiveGenerator.once("startGenerator", this.start, this); this._arrowPrimitiveGenerator.once("endGenerator", this.endArrowPrimitiveGenerator, this); this._arrowPrimitiveGenerator.once("abortGenerator", this.abortArrowPrimitiveGenerator, this); } else { this._textPrimitiveGenerator = new MedsurfDraw.TextPrimitiveGenerator({ target: this.target, layerGroup: this.data.layerGroup, image: this.data.image, stickMode: MedsurfDraw.StickMode.NOELEMENTS, startElement: positionPoint, rotateWithLine: false, withScaling: false, triggerImmediateEndDraw: true }); this._textPrimitiveGenerator.once("startGenerator", this.startTextPrimitiveGenerator, this); this._textPrimitiveGenerator.once("endGenerator", this.endTextPrimitiveGenerator, this); this._textPrimitiveGenerator.once("abortGenerator", this.abortTextPrimitiveGenerator, this); } }; ArrowGenerator.prototype.destroyText = function () { this.end(); if (this._lineElement) { this._lineElement.modeInteraction.setMode('delete_draw'); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.destroy(); } }; ArrowGenerator.prototype.endArrowPrimitiveGenerator = function () { if (!this._startPositionPointElement) { this._startPositionPointElement = this._arrowPrimitiveGenerator.positionPointElement; } this._state = ArrowGeneratorStates.TEXT; this._setupGenerator(); }; ArrowGenerator.prototype.abortArrowPrimitiveGenerator = function () { this.emit("abortGenerator"); this.destroy(); }; ArrowGenerator.prototype.startTextPrimitiveGenerator = function () { this._lineElement = MedsurfDraw.Line.getInstance(this.target, this._arrowPrimitiveGenerator.positionPointElement.name, this._textPrimitiveGenerator.positionPointElement.name, false, this.target.dimensions.width); this.target.addChild(this._lineElement); this._lineElement.controlDrawItem(true); this._lineElement.showItem(); this.target.addImageObject(this._lineElement.model, this.data.layerGroup, this.data.image); }; ArrowGenerator.prototype.endTextPrimitiveGenerator = function () { this._lineElement.modeInteraction.setModeItem('draw_select_new'); this.emit("endGenerator"); this.end(); }; ArrowGenerator.prototype.abortTextPrimitiveGenerator = function () { this.destroyText(); this.emit("endGenerator"); }; Object.defineProperty(ArrowGenerator.prototype, "drawInteraction", { get: function () { if (this._state === ArrowGeneratorStates.ARROW) { return this._arrowPrimitiveGenerator.drawInteraction; } else { return this._textPrimitiveGenerator.drawInteraction; } }, enumerable: false, configurable: true }); return ArrowGenerator; }(BaseGenerator)); export { ArrowGenerator }; //# sourceMappingURL=ArrowGenerator.js.map