medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
182 lines • 8.43 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 } from "../../bases/generators/BaseGenerator";
import { FillGeneratorModel } from "../fills/FillGenerator";
export var InteractiveAreaGeneratorStates;
(function (InteractiveAreaGeneratorStates) {
InteractiveAreaGeneratorStates[InteractiveAreaGeneratorStates["FILL"] = 0] = "FILL";
InteractiveAreaGeneratorStates[InteractiveAreaGeneratorStates["TEXT"] = 1] = "TEXT";
})(InteractiveAreaGeneratorStates || (InteractiveAreaGeneratorStates = {}));
var InteractiveAreaGeneratorModel = (function (_super) {
__extends(InteractiveAreaGeneratorModel, _super);
function InteractiveAreaGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return InteractiveAreaGeneratorModel;
}(FillGeneratorModel));
export { InteractiveAreaGeneratorModel };
var InteractiveAreaGenerator = (function (_super) {
__extends(InteractiveAreaGenerator, _super);
function InteractiveAreaGenerator(model) {
var _this = _super.call(this, model) || this;
_this._state = InteractiveAreaGeneratorStates.FILL;
_this.target.modeInteraction.setModeItem("drawing");
_this._setupGenerator();
return _this;
}
InteractiveAreaGenerator.prototype.end = function () {
if (this._fillGenerator) {
this._fillGenerator.removeAllListeners();
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.removeAllListeners();
}
_super.prototype.end.call(this);
};
InteractiveAreaGenerator.prototype.destroy = function (options) {
this.end();
if (this._lineElement && this._lineElement.modeInteraction.lastMode.endsWith('_new')) {
this._lineElement.modeInteraction.setMode('delete_draw');
}
if (this._fillGenerator) {
this._fillGenerator.destroy();
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.destroy();
}
};
InteractiveAreaGenerator.prototype.endGenerator = function () {
_super.prototype.endGenerator.call(this);
this._fillCollectionElement.onButtonSetInteractive(true);
this._fillCollectionElement.model.interactiveItems = 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);
};
InteractiveAreaGenerator.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);
};
InteractiveAreaGenerator.prototype._setupGenerator = function (positionPoint) {
if (this._state === InteractiveAreaGeneratorStates.FILL) {
this._fillGenerator = new MedsurfDraw.FillGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: this.stickMode,
bezierCourve: this.bezierCourve,
startElement: positionPoint
});
this._fillGenerator.once("startGenerator", this.start, this);
this._fillGenerator.once("endGenerator", this.endInteractiveAreaGenerator, this);
this._fillGenerator.once("abortGenerator", this.abortInteractiveAreaGenerator, 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);
}
};
InteractiveAreaGenerator.prototype.destroyText = function () {
this.end();
if (this._lineElement) {
this._lineElement.modeInteraction.setMode('delete_draw');
}
if (this._textPrimitiveGenerator) {
this._textPrimitiveGenerator.destroy();
}
};
InteractiveAreaGenerator.prototype.endInteractiveAreaGenerator = function () {
if (!this._fillCollectionElement) {
this._fillCollectionElement = this._fillGenerator.fillCollectionElement;
}
this._state = InteractiveAreaGeneratorStates.TEXT;
this._setupGenerator();
};
InteractiveAreaGenerator.prototype.abortInteractiveAreaGenerator = function () {
this.destroy();
this.emit("abortGenerator");
};
InteractiveAreaGenerator.prototype.startTextPrimitiveGenerator = function () {
this._lineElement = MedsurfDraw.Line.getInstance(this.target, this._fillGenerator.fillCollectionElement.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);
};
InteractiveAreaGenerator.prototype.endTextPrimitiveGenerator = function () {
this._lineElement.modeInteraction.setModeItem('draw_select_new');
this.emit("endGenerator");
this.end();
};
InteractiveAreaGenerator.prototype.abortTextPrimitiveGenerator = function () {
this.destroyText();
this.emit("endGenerator");
};
Object.defineProperty(InteractiveAreaGenerator.prototype, "drawInteraction", {
get: function () {
if (this._state === InteractiveAreaGeneratorStates.FILL) {
return this._fillGenerator.drawInteraction;
}
else {
return this._textPrimitiveGenerator.drawInteraction;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(InteractiveAreaGenerator.prototype, "bezierCourve", {
get: function () {
return this.data.bezierCourve;
},
set: function (value) {
this.data.bezierCourve = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(InteractiveAreaGenerator.prototype, "stickMode", {
get: function () {
return this.data.stickMode;
},
set: function (value) {
this.data.stickMode = value;
},
enumerable: false,
configurable: true
});
return InteractiveAreaGenerator;
}(BaseGenerator));
export { InteractiveAreaGenerator };
//# sourceMappingURL=InteractiveAreaGenerator.js.map