UNPKG

medsurf-draw

Version:

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

163 lines 7.76 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 EllipseGeneratorStates; (function (EllipseGeneratorStates) { EllipseGeneratorStates[EllipseGeneratorStates["ELLIPSE"] = 0] = "ELLIPSE"; EllipseGeneratorStates[EllipseGeneratorStates["TEXT"] = 1] = "TEXT"; })(EllipseGeneratorStates || (EllipseGeneratorStates = {})); var EllipseGeneratorModel = (function (_super) { __extends(EllipseGeneratorModel, _super); function EllipseGeneratorModel() { return _super !== null && _super.apply(this, arguments) || this; } return EllipseGeneratorModel; }(BaseGeneratorModel)); export { EllipseGeneratorModel }; var EllipseGenerator = (function (_super) { __extends(EllipseGenerator, _super); function EllipseGenerator(model) { var _this = _super.call(this, model) || this; _this._state = EllipseGeneratorStates.ELLIPSE; _this.target.modeInteraction.setModeItem("drawing"); _this._setupGenerator(); return _this; } EllipseGenerator.prototype.end = function () { if (this._ellipsePrimitiveGenerator) { this._ellipsePrimitiveGenerator.removeAllListeners(); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.removeAllListeners(); } _super.prototype.end.call(this); }; EllipseGenerator.prototype.destroy = function (options) { this.end(); if (this._lineElement && this._lineElement.modeInteraction.lastMode.endsWith('new')) { this._lineElement.modeInteraction.setMode('delete_draw'); } if (this._ellipsePrimitiveGenerator) { this._ellipsePrimitiveGenerator.destroy(); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.destroy(); } }; EllipseGenerator.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); }; EllipseGenerator.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); }; EllipseGenerator.prototype._setupGenerator = function (positionPoint) { if (this._state === EllipseGeneratorStates.ELLIPSE) { this._ellipsePrimitiveGenerator = new MedsurfDraw.EllipsePrimitiveGenerator({ target: this.target, layerGroup: this.data.layerGroup, image: this.data.image, stickMode: MedsurfDraw.StickMode.NOELEMENTS, startElement: positionPoint, rotateWithLine: false, withScaling: true, triggerImmediateEndDraw: true }); this._ellipsePrimitiveGenerator.once("startGenerator", this.start, this); this._ellipsePrimitiveGenerator.once("endGenerator", this.endEllipsePrimitiveGenerator, this); this._ellipsePrimitiveGenerator.once("abortGenerator", this.abortEllipsePrimitiveGenerator, 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); } }; EllipseGenerator.prototype.destroyText = function () { this.end(); if (this._lineElement) { this._lineElement.modeInteraction.setMode('delete_draw'); } if (this._textPrimitiveGenerator) { this._textPrimitiveGenerator.destroy(); } }; EllipseGenerator.prototype.endEllipsePrimitiveGenerator = function () { if (!this._startPositionPointElement) { this._startPositionPointElement = this._ellipsePrimitiveGenerator.positionPointElement; } this._state = EllipseGeneratorStates.TEXT; this._setupGenerator(); }; EllipseGenerator.prototype.abortEllipsePrimitiveGenerator = function () { this.destroy(); this.emit("abortGenerator"); }; EllipseGenerator.prototype.startTextPrimitiveGenerator = function () { this._lineElement = MedsurfDraw.Line.getInstance(this.target, this._ellipsePrimitiveGenerator.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); }; EllipseGenerator.prototype.endTextPrimitiveGenerator = function () { this._lineElement.modeInteraction.setModeItem('draw_select_new'); this.emit("endGenerator"); this.end(); }; EllipseGenerator.prototype.abortTextPrimitiveGenerator = function () { this.destroyText(); this.emit("endGenerator"); }; Object.defineProperty(EllipseGenerator.prototype, "drawInteraction", { get: function () { if (this._state === EllipseGeneratorStates.ELLIPSE) { return this._ellipsePrimitiveGenerator.drawInteraction; } else { return this._textPrimitiveGenerator.drawInteraction; } }, enumerable: false, configurable: true }); return EllipseGenerator; }(BaseGenerator)); export { EllipseGenerator }; //# sourceMappingURL=EllipseGenerator.js.map