medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
255 lines • 12.2 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 PIXI from "pixi.js-legacy";
import * as MedsurfDraw from "../../public-api";
import { BaseGenerator } from "../../bases/generators/BaseGenerator";
import { PositionPointGeneratorModel } from "../positionings/PositionPointGenerator";
var RectanglePrimitiveGeneratorModel = (function (_super) {
__extends(RectanglePrimitiveGeneratorModel, _super);
function RectanglePrimitiveGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return RectanglePrimitiveGeneratorModel;
}(PositionPointGeneratorModel));
export { RectanglePrimitiveGeneratorModel };
var RectanglePrimitiveGenerator = (function (_super) {
__extends(RectanglePrimitiveGenerator, _super);
function RectanglePrimitiveGenerator(model) {
var _this = _super.call(this, model) || this;
_this.target.modeInteraction.setModeItem("drawing");
if (!_this.startElement) {
_this._positionPointGenerator = new MedsurfDraw.PositionPointGenerator({
target: _this.target,
layerGroup: _this.data.layerGroup,
image: _this.data.image,
stickMode: _this.stickMode
});
_this._positionPointGenerator.once("startGenerator", _this.start, _this);
_this._positionPointGenerator.once("startGenerator", _this.startPositionPointGenerator, _this);
_this._positionPointGenerator.once("updatePoint", _this.updatePositionPointGenerator, _this);
if (_this.withScaling) {
_this._positionPointGenerator.once("endGenerator", _this.endPositionPointGeneratorScale, _this);
_this._positionPointGenerator.once("endGenerator", _this.startScale, _this);
}
else {
_this._positionPointGenerator.once("endGenerator", _this.endPositionPointGenerator, _this);
}
_this._positionPointGenerator.once("abortGenerator", _this.abortPositionPointGenerator, _this);
}
else {
_this.startPositionPointGenerator();
if (_this.withScaling) {
_this.endPositionPointGeneratorScale();
var globalPoint = _this.target.renderer.plugins.interaction.mouse.global;
var hitTest = _this.target.renderer.plugins.interaction.hitTest(globalPoint, _this.target);
if (!hitTest) {
_this.target.once("pointerover", _this.startScale, _this);
}
else {
_this.startScale();
}
}
else {
_this.endPositionPointGenerator();
}
}
return _this;
}
RectanglePrimitiveGenerator.prototype.start = function (event) {
this.emit("startGenerator");
};
RectanglePrimitiveGenerator.prototype.end = function () {
this.target.parent.off("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction);
this.target.parent.off("rightup", this.drawInteraction.abortDraw, this.drawInteraction);
this.target.parent.off("pointermove", this.drawInteraction.onDraw, this.drawInteraction);
this.target.parent.off("mouseup", this.drawInteraction.endDraw, this.drawInteraction);
this.drawInteraction.removeAllListeners();
if (this._positionPointGenerator) {
this._positionPointGenerator.removeAllListeners();
}
_super.prototype.end.call(this);
};
RectanglePrimitiveGenerator.prototype.destroy = function (options) {
this.end();
if (this.rectanglePrimitiveElement) {
this.rectanglePrimitiveElement.modeInteraction.setMode('delete_draw');
}
if (this._positionPointGenerator) {
this._positionPointGenerator.destroy();
}
};
RectanglePrimitiveGenerator.prototype.endGenerator = function () {
_super.prototype.endGenerator.call(this);
this.target.sortChildren();
this.target.modeInteraction.setMode(this.target.modeInteraction.defaultMode);
};
RectanglePrimitiveGenerator.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);
};
RectanglePrimitiveGenerator.prototype.startPositionPointGenerator = function () {
this._rectanglePrimitiveElement = MedsurfDraw.RectanglePrimitive.getInstance(this.target, this.rotateWithLine, this.target.dimensions.width);
this.positionPointElement.addChild(this.rectanglePrimitiveElement);
this.rectanglePrimitiveElement.controlDrawItem();
this.rectanglePrimitiveElement.showItem();
this._drawInteraction = new MedsurfDraw.DrawInteraction(this.rectanglePrimitiveElement, MedsurfDraw.StickMode.NOELEMENTS);
};
RectanglePrimitiveGenerator.prototype.updatePositionPointGenerator = function () {
this.startPositionPointGenerator();
if (this.withScaling) {
this.endPositionPointGeneratorScale();
this.startScale();
}
else {
this.endPositionPointGenerator();
}
};
RectanglePrimitiveGenerator.prototype.endPositionPointGeneratorScale = function () {
if (!this.positionPointElement.model.primitives) {
this.positionPointElement.model.primitives = [];
}
this.positionPointElement.model.primitives.push(this.rectanglePrimitiveElement.model);
if (!this.withScaling && this.triggerImmediateEndDraw) {
this.endRectanglePrimitiveDraw();
}
else {
this.target.parent.on("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction);
this.target.parent.on("rightup", this.drawInteraction.abortDraw, this.drawInteraction);
this.target.parent.on("pointermove", this.drawInteraction.onDraw, this.drawInteraction);
this.target.parent.on("mouseup", this.drawInteraction.endDraw, this.drawInteraction);
this.drawInteraction.on("startScale", this.rectanglePrimitiveElement.scaleInteraction.startScale, this.rectanglePrimitiveElement.scaleInteraction);
this.drawInteraction.on("onScale", this.rectanglePrimitiveElement.scaleInteraction.onScale, this.rectanglePrimitiveElement.scaleInteraction);
this.drawInteraction.on("endScale", this.rectanglePrimitiveElement.scaleInteraction.endScale, this.rectanglePrimitiveElement.scaleInteraction);
this.drawInteraction.on("endDraw", this.endRectanglePrimitiveDraw, this);
this.drawInteraction.on("abortDraw", this.abortRectanglePrimitiveDraw, this);
}
};
RectanglePrimitiveGenerator.prototype.endPositionPointGenerator = function () {
if (!this.positionPointElement.model.primitives) {
this.positionPointElement.model.primitives = [];
}
this.positionPointElement.model.primitives.push(this.rectanglePrimitiveElement.model);
if (!this.withScaling && this.triggerImmediateEndDraw) {
this.endRectanglePrimitiveDraw();
}
else {
this.target.parent.on("mousedown", this.drawInteraction.startDrawScale, this.drawInteraction);
this.target.parent.on("rightup", this.drawInteraction.abortDraw, this.drawInteraction);
this.target.parent.on("pointermove", this.drawInteraction.onDraw, this.drawInteraction);
this.target.parent.on("mouseup", this.drawInteraction.endDraw, this.drawInteraction);
this.drawInteraction.on("endDraw", this.endRectanglePrimitiveDraw, this);
this.drawInteraction.on("abortDraw", this.abortRectanglePrimitiveDraw, this);
}
};
RectanglePrimitiveGenerator.prototype.startScale = function () {
var event = new PIXI.InteractionEvent();
event.data = new PIXI.InteractionData();
event.data.global = this.target.renderer.plugins.interaction.mouse.global;
this.drawInteraction.startDrawScale(event);
};
RectanglePrimitiveGenerator.prototype.abortPositionPointGenerator = function () {
this.emit("abortGenerator");
this.destroy();
};
RectanglePrimitiveGenerator.prototype.endRectanglePrimitiveDraw = function () {
this.emit("endGenerator");
this.end();
};
RectanglePrimitiveGenerator.prototype.abortRectanglePrimitiveDraw = function () {
this.emit("abortGenerator");
this.destroy();
};
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "drawInteraction", {
get: function () {
return this._drawInteraction;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "positionPointElement", {
get: function () {
return this.startElement ? this.startElement : this._positionPointGenerator.positionPointElement;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "rectanglePrimitiveElement", {
get: function () {
return this._rectanglePrimitiveElement;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "stickMode", {
get: function () {
return this.data.stickMode;
},
set: function (value) {
this.data.stickMode = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "startElement", {
get: function () {
return this.data.startElement;
},
set: function (value) {
this.data.startElement = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "rotateWithLine", {
get: function () {
return this.data.rotateWithLine;
},
set: function (value) {
this.data.rotateWithLine = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "withScaling", {
get: function () {
return this.data.withScaling;
},
set: function (value) {
this.data.withScaling = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitiveGenerator.prototype, "triggerImmediateEndDraw", {
get: function () {
return this.data.triggerImmediateEndDraw;
},
set: function (value) {
this.data.triggerImmediateEndDraw = value;
},
enumerable: false,
configurable: true
});
return RectanglePrimitiveGenerator;
}(BaseGenerator));
export { RectanglePrimitiveGenerator };
//# sourceMappingURL=RectanglePrimitiveGenerator.js.map