medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
210 lines • 9.98 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 * as Models from '@ascii-dev-user/medsurf-lib/models';
import { BaseGenerator } from "../../bases/generators/BaseGenerator";
import { MarkerGeneratorModel } from "./MarkerGenerator";
export var PrimitiveMarkerGeneratorStates;
(function (PrimitiveMarkerGeneratorStates) {
PrimitiveMarkerGeneratorStates[PrimitiveMarkerGeneratorStates["PRIMITIVE"] = 0] = "PRIMITIVE";
PrimitiveMarkerGeneratorStates[PrimitiveMarkerGeneratorStates["MARKER"] = 1] = "MARKER";
})(PrimitiveMarkerGeneratorStates || (PrimitiveMarkerGeneratorStates = {}));
var PrimitiveMarkerGeneratorModel = (function (_super) {
__extends(PrimitiveMarkerGeneratorModel, _super);
function PrimitiveMarkerGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return PrimitiveMarkerGeneratorModel;
}(MarkerGeneratorModel));
export { PrimitiveMarkerGeneratorModel };
var ArrowMarkerGeneratorModel = (function (_super) {
__extends(ArrowMarkerGeneratorModel, _super);
function ArrowMarkerGeneratorModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return ArrowMarkerGeneratorModel;
}(PrimitiveMarkerGeneratorModel));
export { ArrowMarkerGeneratorModel };
var PrimitiveMarkerGenerator = (function (_super) {
__extends(PrimitiveMarkerGenerator, _super);
function PrimitiveMarkerGenerator(model) {
var _this = _super.call(this, model) || this;
_this._enableKeyEvents = false;
_this._state = PrimitiveMarkerGeneratorStates.PRIMITIVE;
_this.target.modeInteraction.setModeItem("drawing");
_this._setupGenerator();
return _this;
}
PrimitiveMarkerGenerator.prototype.end = function () {
if (this._primitiveGenerator) {
this._primitiveGenerator.removeAllListeners();
}
if (this._markerGenerator) {
this._markerGenerator.removeAllListeners();
}
_super.prototype.end.call(this);
};
PrimitiveMarkerGenerator.prototype.destroy = function (options) {
this.end();
if (this._primitiveGenerator) {
this._primitiveGenerator.destroy();
}
if (this._markerGenerator) {
this._markerGenerator.destroy();
}
};
PrimitiveMarkerGenerator.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);
};
PrimitiveMarkerGenerator.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);
};
PrimitiveMarkerGenerator.prototype._setupGenerator = function (positionPoint) {
if (this._state === PrimitiveMarkerGeneratorStates.PRIMITIVE) {
switch (this.type) {
case Models.ImageObjectType.ARROW:
this._primitiveGenerator = new MedsurfDraw.ArrowPrimitiveGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: MedsurfDraw.StickMode.NOELEMENTS,
startElement: positionPoint,
hasWedgePoint: this.data.hasWedgePoint,
rotateWithLine: this.data.rotateWithLine,
withScaling: false,
triggerImmediateEndDraw: true
});
break;
case Models.ImageObjectType.ELLIPSE:
this._primitiveGenerator = new MedsurfDraw.EllipsePrimitiveGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: MedsurfDraw.StickMode.NOELEMENTS,
startElement: positionPoint,
rotateWithLine: this.data.rotateWithLine,
withScaling: false,
triggerImmediateEndDraw: true
});
break;
case Models.ImageObjectType.RECTANGLE:
this._primitiveGenerator = new MedsurfDraw.RectanglePrimitiveGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: MedsurfDraw.StickMode.NOELEMENTS,
startElement: positionPoint,
rotateWithLine: this.data.rotateWithLine,
withScaling: false,
triggerImmediateEndDraw: true
});
break;
case Models.ImageObjectType.TEXT:
this._primitiveGenerator = new MedsurfDraw.TextPrimitiveGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
stickMode: MedsurfDraw.StickMode.NOELEMENTS,
startElement: positionPoint,
rotateWithLine: this.data.rotateWithLine,
withScaling: false,
triggerImmediateEndDraw: true
});
break;
default:
this._state = PrimitiveMarkerGeneratorStates.MARKER;
return this._setupGenerator(positionPoint);
}
this._primitiveGenerator.once("startGenerator", this.start, this);
this._primitiveGenerator.once("endGenerator", this.endPrimitiveGenerator, this);
this._primitiveGenerator.once("abortGenerator", this.abortPrimitiveGenerator, this);
}
else {
this._markerGenerator = new MedsurfDraw.MarkerGenerator({
target: this.target,
layerGroup: this.data.layerGroup,
image: this.data.image,
startElement: this._startPositionPointElement
});
this._markerGenerator.once("endGenerator", this.endMarkerGenerator, this);
this._markerGenerator.once("abortGenerator", this.abortMarkerGenerator, this);
}
};
PrimitiveMarkerGenerator.prototype.endPrimitiveGenerator = function () {
if (!this._startPositionPointElement) {
this._startPositionPointElement = this._primitiveGenerator.positionPointElement;
}
if (!(MedsurfDraw.Keyboard.isKeyDown("ControlLeft") || MedsurfDraw.Keyboard.isKeyDown("ControlRight"))) {
this._enableKeyEvents = true;
this._state = PrimitiveMarkerGeneratorStates.MARKER;
}
this._setupGenerator(this._primitiveGenerator.positionPointElement);
};
PrimitiveMarkerGenerator.prototype.abortPrimitiveGenerator = function () {
this.emit("abortGenerator");
this.destroy();
};
PrimitiveMarkerGenerator.prototype.endMarkerGenerator = function () {
this.emit("endGenerator");
this.end();
};
PrimitiveMarkerGenerator.prototype.abortMarkerGenerator = function () {
this.emit("abortGenerator");
this.destroy();
};
PrimitiveMarkerGenerator.prototype.onKeyPressed = function (keyCode, event) {
};
PrimitiveMarkerGenerator.prototype.onKeyReleased = function (keyCode, event) {
};
Object.defineProperty(PrimitiveMarkerGenerator.prototype, "drawInteraction", {
get: function () {
if (this._state === PrimitiveMarkerGeneratorStates.PRIMITIVE) {
return this._primitiveGenerator.drawInteraction;
}
else {
return this._markerGenerator.drawInteraction;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(PrimitiveMarkerGenerator.prototype, "type", {
get: function () {
return this.data.type;
},
set: function (value) {
this.data.type = value;
},
enumerable: false,
configurable: true
});
return PrimitiveMarkerGenerator;
}(BaseGenerator));
export { PrimitiveMarkerGenerator };
//# sourceMappingURL=PrimitiveMarkerGenerator.js.map