medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
163 lines • 7.87 kB
JavaScript
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 RectangleGeneratorStates;
(function (RectangleGeneratorStates) {
RectangleGeneratorStates[RectangleGeneratorStates["RECTANGLE"] = 0] = "RECTANGLE";
RectangleGeneratorStates[RectangleGeneratorStates["TEXT"] = 1] = "TEXT";
})(RectangleGeneratorStates || (RectangleGeneratorStates = {}));
var RectangleGeneratorModel = (function (_super) {
__extends(RectangleGeneratorModel, _super);
function RectangleGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return RectangleGeneratorModel;
}(BaseGeneratorModel));
export { RectangleGeneratorModel };
var RectangleGenerator = (function (_super) {
__extends(RectangleGenerator, _super);
function RectangleGenerator(model) {
var _this = _super.call(this, model) || this;
_this._state = RectangleGeneratorStates.RECTANGLE;
_this.target.modeInteraction.setModeItem("drawing");
_this._setupGenerator();
return _this;
}
RectangleGenerator.prototype.end = function () {
if (this._rectanglePrimitiveGenerator) {
this._rectanglePrimitiveGenerator.removeAllListeners();
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.removeAllListeners();
}
_super.prototype.end.call(this);
};
RectangleGenerator.prototype.destroy = function (options) {
this.end();
if (this._lineElement && this._lineElement.modeInteraction.lastMode.endsWith('new')) {
this._lineElement.modeInteraction.setMode('delete_draw');
}
if (this._rectanglePrimitiveGenerator) {
this._rectanglePrimitiveGenerator.destroy();
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.destroy();
}
};
RectangleGenerator.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);
};
RectangleGenerator.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);
};
RectangleGenerator.prototype._setupGenerator = function (positionPoint) {
if (this._state === RectangleGeneratorStates.RECTANGLE) {
this._rectanglePrimitiveGenerator = new MedsurfDraw.RectanglePrimitiveGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: MedsurfDraw.StickMode.NOELEMENTS,
startElement: positionPoint,
rotateWithLine: false,
withScaling: true,
triggerImmediateEndDraw: true
});
this._rectanglePrimitiveGenerator.once("startGenerator", this.start, this);
this._rectanglePrimitiveGenerator.once("endGenerator", this.endRectanglePrimitiveGenerator, this);
this._rectanglePrimitiveGenerator.once("abortGenerator", this.abortRectanglePrimitiveGenerator, 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);
}
};
RectangleGenerator.prototype.destroyText = function () {
this.end();
if (this._lineElement) {
this._lineElement.modeInteraction.setMode('delete_draw');
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.destroy();
}
};
RectangleGenerator.prototype.endRectanglePrimitiveGenerator = function () {
if (!this._startPositionPointElement) {
this._startPositionPointElement = this._rectanglePrimitiveGenerator.positionPointElement;
}
this._state = RectangleGeneratorStates.TEXT;
this._setupGenerator();
};
RectangleGenerator.prototype.abortRectanglePrimitiveGenerator = function () {
this.destroy();
this.emit("abortGenerator");
};
RectangleGenerator.prototype.startTextPrimitiveGenerator = function () {
this._lineElement = MedsurfDraw.Line.getInstance(this.target, this._rectanglePrimitiveGenerator.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);
};
RectangleGenerator.prototype.endTextPrimitiveGenerator = function () {
this._lineElement.modeInteraction.setModeItem('draw_select_new');
this.emit("endGenerator");
this.end();
};
RectangleGenerator.prototype.abortTextPrimitiveGenerator = function () {
this.destroyText();
this.emit("endGenerator");
};
Object.defineProperty(RectangleGenerator.prototype, "drawInteraction", {
get: function () {
if (this._state === RectangleGeneratorStates.RECTANGLE) {
return this._rectanglePrimitiveGenerator.drawInteraction;
}
else {
return this._textPrimitiveGenerator.drawInteraction;
}
},
enumerable: false,
configurable: true
});
return RectangleGenerator;
}(BaseGenerator));
export { RectangleGenerator };
//# sourceMappingURL=RectangleGenerator.js.map