medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
145 lines • 6.4 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 { LineGeneratorModel } from "../connections/LineGenerator";
var FillGeneratorModel = (function (_super) {
__extends(FillGeneratorModel, _super);
function FillGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return FillGeneratorModel;
}(LineGeneratorModel));
export { FillGeneratorModel };
var FillGenerator = (function (_super) {
__extends(FillGenerator, _super);
function FillGenerator(model) {
var _this = _super.call(this, model) || this;
_this.target.modeInteraction.setModeItem("drawing");
_this._lineGenerator = new MedsurfDraw.LineGenerator(_this.data);
_this._lineGenerator.once("startGenerator", _this.start, _this);
_this._lineGenerator.once("startGenerator", _this.startLineGenerator, _this);
_this._lineGenerator.once("endGenerator", _this.endLineGenerator, _this);
_this._lineGenerator.once("abortGenerator", _this.abortLineGenerator, _this);
return _this;
}
FillGenerator.prototype.end = function () {
if (this._lineGenerator) {
this._lineGenerator.off("startGenerator", this.start, this);
this._lineGenerator.off("startGenerator", this.startLineGenerator, this);
this._lineGenerator.off("endGenerator", this.endLineGenerator, this);
this._lineGenerator.off("abortGenerator", this.abortLineGenerator, this);
}
_super.prototype.end.call(this);
};
FillGenerator.prototype.destroy = function (options) {
this.end();
if (this._lineGenerator) {
this._lineGenerator.destroy();
}
};
FillGenerator.prototype.endGenerator = function () {
_super.prototype.endGenerator.call(this);
this.target.sortChildren();
this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode);
};
FillGenerator.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");
});
if (this._fillCollectionElement) {
this._fillCollectionElement.modeInteraction.setMode("delete_draw");
}
this.target.sortChildren();
this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode);
};
FillGenerator.prototype._setupGenerator = function (positionPoint) {
this._lineGenerator = new MedsurfDraw.LineGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
bezierCourve: this.bezierCourve,
stickMode: this.stickMode,
startElement: positionPoint
});
this._lineGenerator.once("endGenerator", this.endLineGenerator, this);
this._lineGenerator.once("abortGenerator", this.abortLineGenerator, this);
};
FillGenerator.prototype.startLineGenerator = function () {
this._fillCollectionElement = MedsurfDraw.FillCollection.getInstance(this.target, []);
this.target.addChild(this._fillCollectionElement);
this.fillCollectionElement.controlDrawItem();
this.target.addImageObject(this._fillCollectionElement.model, this.data.layerGroup, this.data.image);
};
FillGenerator.prototype.endLineGenerator = function () {
this._lineGenerator.startPositionPointElement.modeInteraction.setMode("draw_select");
this._lineGenerator.endPositionPointElement.modeInteraction.setMode("draw_select");
this._lineGenerator.lineElement.modeInteraction.setMode("draw_select");
this.fillCollectionElement.addLine(this._lineGenerator.lineElement);
this.fillCollectionElement.showItem();
if (this._fillCollectionElement.validate()) {
this.emit("endGenerator");
this.end();
}
else {
this._setupGenerator(this._lineGenerator.endPositionPointElement);
}
};
FillGenerator.prototype.abortLineGenerator = function () {
this.emit("abortGenerator");
this.destroy();
};
Object.defineProperty(FillGenerator.prototype, "drawInteraction", {
get: function () {
return this._lineGenerator.drawInteraction;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FillGenerator.prototype, "fillCollectionElement", {
get: function () {
return this._fillCollectionElement;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FillGenerator.prototype, "bezierCourve", {
get: function () {
return this.data.bezierCourve;
},
set: function (value) {
this.data.bezierCourve = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(FillGenerator.prototype, "stickMode", {
get: function () {
return this.data.stickMode;
},
set: function (value) {
this.data.stickMode = value;
},
enumerable: false,
configurable: true
});
return FillGenerator;
}(BaseGenerator));
export { FillGenerator };
//# sourceMappingURL=FillGenerator.js.map