medsurf-draw
Version:
Draw annotations on jpg/zoomify images, based on PIXI.js
909 lines • 44.6 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 __());
};
})();
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import * as PIXI from "pixi.js-legacy";
import * as MedsurfDraw from "../../public-api";
import * as Models from '@ascii-dev-user/medsurf-lib/models';
import { v4 as uuidv4 } from 'uuid';
import { Design } from "../../config/design";
import { BaseElementContainer, ColorMode, NumberMode } from "../../bases/elements/BaseElementContainer";
import { debounce } from "debounce";
var RectanglePrimitive = (function (_super) {
__extends(RectanglePrimitive, _super);
function RectanglePrimitive(image, model) {
var _this = _super.call(this, { image: image, model: model }) || this;
_this._selftestSelected = false;
_this.zIndex = Design.rectanglePrimitive.zIndexDefault + _this.model.zIndex;
_this.rotation = _this.model.angle || 0;
_this.modeInteraction.on("default", _this._modeDefault, _this);
_this.modeInteraction.on("remove-default", _this._removeModeDefault, _this);
_this.modeInteraction.on("marker", _this._modeMarker, _this);
_this.modeInteraction.on("remove-marker", _this._removeModeMarker, _this);
_this.modeInteraction.on("selftest", _this._modeSelftest, _this);
_this.modeInteraction.on("remove-selftest", _this._removeModeSelftest, _this);
_this.modeInteraction.on("author", _this._modeAuthor, _this);
_this.modeInteraction.on("remove-author", _this._removeModeAuthor, _this);
_this.modeInteraction.on('select_layer_group', _this._modeSelectLayerGroup, _this);
_this.modeInteraction.on('remove-select_layer_group', _this._removeModeSelectLayerGroup, _this);
_this.modeInteraction.on('select_grouping', _this._modeSelectGrouping, _this);
_this.modeInteraction.on('remove-select_grouping', _this._removeModeSelectGrouping, _this);
_this.modeInteraction.on('select_item', _this._modeSelectItem, _this);
_this.modeInteraction.on("remove-select_item", _this._removeModeSelectItem, _this);
_this.modeInteraction.on('select_item_color_line', _this._modeSelectItemColor, _this);
_this.modeInteraction.on('remove-select_item_color_line', _this._removeModeSelectItemColorLine, _this);
_this.modeInteraction.on('select_item_color_fill', _this._modeSelectItemColor, _this);
_this.modeInteraction.on("remove-select_item_color_fill", _this._removeModeSelectItemColorFill, _this);
_this.modeInteraction.on('select_item_number_line_width', _this._modeSelectItemNumber, _this);
_this.modeInteraction.on("remove-select_item_number_line_width", _this._removeModeSelectItemNumber, _this);
_this.modeInteraction.on('blocked_item', _this._modeBlockedItem, _this);
_this.modeInteraction.on("remove-blocked_item", _this._removeModeBlockedItem, _this);
_this.modeInteraction.on('draw_item', _this._modeDrawItem, _this);
_this.modeInteraction.on("remove-draw_item", _this._removeModeDrawItem, _this);
_this.modeInteraction.on('draw_clickable', _this._modeDrawSelect, _this);
_this.modeInteraction.on('remove-draw_clickable', _this._removeModeDrawSelect, _this);
_this.modeInteraction.on('choose_select', _this._modeChooseSelect, _this);
_this.modeInteraction.on('remove-choose_select', _this._removeModeChooseSelect, _this);
_this.modeInteraction.on('choose_unselect', _this._modeChooseUnselect, _this);
_this.modeInteraction.on('remove-choose_unselect', _this._removeModeChooseUnselect, _this);
_this.modeInteraction.on("delete", _this._modeDelete, _this);
_this.modeInteraction.on("delete_draw", _this._modeDelete, _this);
_this.moveInteraction = new MedsurfDraw.MoveInteraction(_this);
_this.moveInteraction.on("startMove", _this.startMove, _this);
_this.moveInteraction.on("onMove", _this.onMove, _this);
_this.moveInteraction.on("endMove", _this.endMove, _this);
_this.scaleInteraction = new MedsurfDraw.ScaleInteraction(_this, true);
_this.scaleInteraction.on("onScale", _this.onScale, _this);
_this.selectInteraction = new MedsurfDraw.SelectInteraction(_this);
_this.selectInteraction.on("onHover", _this.onHover, _this);
_this.selectInteraction.on("onOut", _this.onOut, _this);
_this.selectInteraction.on("onSelectStart", _this.onSelectStart, _this);
_this.selectInteraction.on("onSelftest", _this.onSelftest, _this);
_this._debounceControlSelectItemMethod = debounce(_this.controlSelectItem.bind(_this), 10).bind(_this);
_this._debounceControlUnselectItemMethod = debounce(_this.controlUnselectItem.bind(_this), 10).bind(_this);
_this.on("added", function (parent) {
_this.on("debounceControlSelectItem", _this._debounceControlSelectItemMethod);
_this.on("debounceControlUnselectItem", _this._debounceControlUnselectItemMethod);
parent.on("endPositionPointMove", _this.endPositionPointMove, _this);
parent.on("selftestChanged", _this.selftestChanged, _this);
_this._selftestElement.selectInteraction.on("onSelftest", _this.onSelftest, _this);
});
_this.on("removed", function (parent) {
_this.off("debounceControlSelectItem", _this._debounceControlSelectItemMethod);
_this.off("debounceControlUnselectItem", _this._debounceControlUnselectItemMethod);
parent.off("endPositionPointMove", _this.endPositionPointMove, _this);
parent.off("selftestChanged", _this.selftestChanged, _this);
_this._selftestElement.selectInteraction.off("onSelftest", _this.onSelftest, _this);
});
return _this;
}
RectanglePrimitive.prototype.init = function () {
var imageWidth = this.imageDimensions.width;
this.position.set(this.model.rectangle.x * imageWidth, this.model.rectangle.y * imageWidth);
this._rectangleElement = new MedsurfDraw.Rectangle({
rectangle: new PIXI.Rectangle(0, 0, this.model.rectangle.width * imageWidth, this.model.rectangle.height * imageWidth),
options: Object.assign({}, this.model.options),
lineWidth: this.model.strokeWidth ? Math.round(this.model.strokeWidth * imageWidth * 100) / 100 : undefined
});
this.addChild(this._rectangleElement);
this._selftestElement = new MedsurfDraw.SelftestPoint({
image: this.image,
isSelftest: this.parent.model.isSelftest,
selftestPoint: new PIXI.Point(this.parent.x + this.model.rectangle.x * imageWidth, this.parent.y + this.model.rectangle.y * imageWidth),
options: Object.assign({}, this.model.options),
});
this.image.parent.addChild(this._selftestElement);
this._editButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf3f0',
description: 'Bearbeiten',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._editButtonElement.on("onHover", this.collapseAllMenus, this);
this._editButtonElement.on("button", this.onButtonEdit, this);
this.imageObjectMenu.push({
element: this._editButtonElement,
order: 0,
});
this._moveToBackButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf87f',
description: 'Nach Hinten\nverschieben',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._moveToBackButtonElement.on("button", this.onButtonMoveToBack, this);
this._moveToFrontButtonElement = new MedsurfDraw.RoundSubMenuElement({
image: this.image,
text: '\uf856',
description: 'Nach Vorne\nverschieben',
descriptionFontSize: Design.subMenu.descriptionFontSize,
menuElements: [
{
element: this._moveToBackButtonElement,
order: 0,
}
],
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius)
});
this._moveToFrontButtonElement.on("onHover", this._moveToFrontButtonElement.showMenu, this._moveToFrontButtonElement);
this._moveToFrontButtonElement.on("button", this.onButtonMoveToFront, this);
this._moveToFrontButtonElement.on("toggleMenu", this.onMenuLayer, this);
this.imageObjectMenu.push({
element: this._moveToFrontButtonElement,
order: 7,
});
this._deleteButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf1f8',
description: 'Löschen',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._deleteButtonElement.on("onHover", this.collapseAllMenus, this);
this._deleteButtonElement.on("button", this.onButtonDelete, this);
this.imageObjectMenu.push({
element: this._deleteButtonElement,
order: 6,
});
this._degroupButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf248',
description: 'Aus Gruppe\nentfernen',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._degroupButtonElement.on("onHover", this.collapseAllMenus, this);
this._degroupButtonElement.on("button", this.onButtonDegroup, this);
this.imageObjectMenu.push({
element: this._degroupButtonElement,
order: 4,
});
this._horizontalMirrorButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf89c',
description: 'Horizontal\nspiegeln',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._horizontalMirrorButtonElement.on("button", this.onButtonHorizontalMirror, this);
this._verticalMirrorButtonElement = new MedsurfDraw.RoundSubMenuElement({
image: this.image,
text: '\uf89d',
description: 'Vertikal\nspiegeln',
descriptionFontSize: Design.subMenu.descriptionFontSize,
menuElements: [
{
element: this._horizontalMirrorButtonElement,
order: 0,
}
],
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius)
});
this._verticalMirrorButtonElement.on("onHover", this._verticalMirrorButtonElement.showMenu, this._verticalMirrorButtonElement);
this._verticalMirrorButtonElement.on("button", this.onButtonVerticalMirror, this);
this._verticalMirrorButtonElement.on("toggleMenu", this.onMenuMirror, this);
this.imageObjectMenu.push({
element: this._verticalMirrorButtonElement,
order: 3,
});
this._duplicateButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf24d',
description: 'Duplizieren',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._duplicateButtonElement.on("onHover", this.collapseAllMenus, this);
this._duplicateButtonElement.on("button", this.onButtonDuplicate, this);
this.imageObjectMenu.push({
element: this._duplicateButtonElement,
order: 2,
});
this._clipboardButtonElement = new MedsurfDraw.RoundButtonElement({
image: this.image,
text: '\uf0c5',
description: 'Kopieren',
descriptionFontSize: Design.subMenu.descriptionFontSize,
circle: new PIXI.Circle(0, 0, Design.subMenu.buttonRadius),
fontSize: Design.subMenu.fontSize,
fontColor: Design.subMenu.fontColor
});
this._clipboardButtonElement.on("onHover", this.collapseAllMenus, this);
this._clipboardButtonElement.on("button", this.onButtonClipboard, this);
this.imageObjectMenu.push({
element: this._clipboardButtonElement,
order: 1,
});
if (this.model.rotateWithLine) {
this.parent.on("onRotateWithLine", this.onRotateWithLine, this);
this.onRotateWithLine(new PIXI.InteractionEvent());
}
this.sortChildren();
this.emit("debounceDraw");
};
RectanglePrimitive.prototype.draw = function () {
this._rectangleElement.draw();
this._rectangleElement.pivot.set(this._rectangleElement.rectangle.width / 2, this._rectangleElement.rectangle.height / 2);
};
RectanglePrimitive.prototype.destroy = function (options) {
if (this.parent) {
this.parent.off("onRotateWithLine", this.onRotateWithLine, this);
}
if (this.moveInteraction) {
this.moveInteraction.removeAllListeners();
}
if (this.scaleInteraction) {
this.scaleInteraction.removeAllListeners();
}
if (this.selectInteraction) {
this.selectInteraction.removeAllListeners();
}
if (this._rectangleElement) {
this._rectangleElement.destroy(options);
}
if (this._selftestElement) {
this._selftestElement.destroy(options);
}
if (this._editButtonElement) {
this._editButtonElement.destroy(options);
}
if (this._moveToBackButtonElement) {
this._moveToBackButtonElement.destroy(options);
}
if (this._moveToFrontButtonElement) {
this._moveToFrontButtonElement.destroy(options);
}
if (this._deleteButtonElement) {
this._deleteButtonElement.destroy(options);
}
if (this._degroupButtonElement) {
this._degroupButtonElement.destroy(options);
}
if (this._horizontalMirrorButtonElement) {
this._horizontalMirrorButtonElement.destroy(options);
}
if (this._verticalMirrorButtonElement) {
this._verticalMirrorButtonElement.destroy(options);
}
if (this._duplicateButtonElement) {
this._duplicateButtonElement.destroy(options);
}
if (this._clipboardButtonElement) {
this._clipboardButtonElement.destroy(options);
}
_super.prototype.destroy.call(this, options);
};
RectanglePrimitive.getInstance = function (image, rotateWithLine, imageWidth) {
return new RectanglePrimitive(image, {
dirty: true,
id: uuidv4(),
type: Models.ImageObjectType.RECTANGLE,
isStatic: false,
zIndex: 0,
rotateWithLine: rotateWithLine,
rectangle: {
x: 0,
y: 0,
width: 21 / imageWidth,
height: 21 / imageWidth
},
strokeWidth: 1 / imageWidth,
dashFill: 2,
dashEmpty: 2,
options: {
hasLine: true,
lineColor: 0x000000,
lineAlpha: 1,
hasFill: true,
fillColor: 0xffffff,
fillAlpha: 0.3,
}
});
};
RectanglePrimitive.prototype._modeDefault = function () {
this._selftestSelected = false;
if (this.model.isStatic) {
this.showItem();
}
else {
this.hideItem();
}
};
RectanglePrimitive.prototype._removeModeDefault = function () {
};
RectanglePrimitive.prototype._modeMarker = function () {
this._selftestSelected = false;
this.showItem();
};
RectanglePrimitive.prototype._removeModeMarker = function () {
};
RectanglePrimitive.prototype._modeSelftest = function () {
var positionPoint = this.parent;
if (this.model.isStatic) {
this.interactive = true;
this.cursor = "select";
this.showItem();
this.emit("debounceDraw");
}
else if (positionPoint.model.isSelftest) {
this.interactive = true;
this.cursor = "select";
this._rectangleElement.hideItem();
this.showItem();
this.emit("debounceDraw");
}
else {
this.hideItem();
}
};
RectanglePrimitive.prototype._removeModeSelftest = function () {
this.interactive = false;
this._rectangleElement.showItem();
};
RectanglePrimitive.prototype._modeAuthor = function () {
this.interactive = true;
this._selftestSelected = false;
this.on("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.on("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.on("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.on("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
this.showItem();
};
RectanglePrimitive.prototype._removeModeAuthor = function () {
this.interactive = false;
this.off("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.off("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.off("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.off("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
};
RectanglePrimitive.prototype._modeSelectLayerGroup = function () {
this.onOut();
this.interactive = true;
this.on("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.on("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.on("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.on("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
this.showItem();
};
RectanglePrimitive.prototype._removeModeSelectLayerGroup = function () {
this.interactive = false;
this.off("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.off("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.off("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.off("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
};
RectanglePrimitive.prototype._modeSelectGrouping = function () {
this.interactive = true;
this.on("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.on("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.on("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.on("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
this.showItem();
};
RectanglePrimitive.prototype._removeModeSelectGrouping = function () {
this.interactive = false;
this.off("pointerover", this.selectInteraction.onHover, this.selectInteraction);
this.off("pointerout", this.selectInteraction.onOut, this.selectInteraction);
this.off("mousedown", this.selectInteraction.onPointerDown, this.selectInteraction);
this.off("mouseup", this.selectInteraction.onSelect, this.selectInteraction);
};
RectanglePrimitive.prototype._modeSelectItem = function () {
this.onOut();
this.interactive = true;
this.on("pointerover", this.moveInteraction.onMoveHover, this.moveInteraction);
this.on("mousedown", this.moveInteraction.startMove, this.moveInteraction);
this.on("pointermove", this.moveInteraction.onMove, this.moveInteraction);
this.on("mouseup", this.moveInteraction.endMove, this.moveInteraction);
MedsurfDraw.Keyboard.events.on("down_ArrowUp", "onPositionPointMoveUp", this.moveInteraction.moveUp.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("down_ArrowRight", "onPositionPointMoveRight", this.moveInteraction.moveRight.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("down_ArrowDown", "onPositionPointMoveDown", this.moveInteraction.moveDown.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("down_ArrowLeft", "onPositionPointMoveLeft", this.moveInteraction.moveLeft.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("released_ArrowUp", "onPositionPointMoveUpEnd", this.moveInteraction.moveRelease.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("released_ArrowRight", "onPositionPointMoveRightEnd", this.moveInteraction.moveRelease.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("released_ArrowDown", "onPositionPointMoveDownEnd", this.moveInteraction.moveRelease.bind(this.moveInteraction));
MedsurfDraw.Keyboard.events.on("released_ArrowLeft", "onPositionPointMoveLeftEnd", this.moveInteraction.moveRelease.bind(this.moveInteraction));
this.image.controlUpdateElements();
this.showItem();
this.emit("pointerover", new PIXI.InteractionEvent());
};
RectanglePrimitive.prototype._removeModeSelectItem = function (parent, mode) {
this.interactive = false;
this.off("pointerover", this.moveInteraction.onMoveHover, this.moveInteraction);
this.off("mousedown", this.moveInteraction.startMove, this.moveInteraction);
this.off("pointermove", this.moveInteraction.onMove, this.moveInteraction);
this.off("mouseup", this.moveInteraction.endMove, this.moveInteraction);
MedsurfDraw.Keyboard.events.remove("down_ArrowUp", "onPositionPointMoveUp");
MedsurfDraw.Keyboard.events.remove("down_ArrowRight", "onPositionPointMoveRight");
MedsurfDraw.Keyboard.events.remove("down_ArrowDown", "onPositionPointMoveDown");
MedsurfDraw.Keyboard.events.remove("down_ArrowLeft", "onPositionPointMoveLeft");
MedsurfDraw.Keyboard.events.remove("released_ArrowUp", "onPositionPointMoveUpEnd");
MedsurfDraw.Keyboard.events.remove("released_ArrowRight", "onPositionPointMoveRightEnd");
MedsurfDraw.Keyboard.events.remove("released_ArrowDown", "onPositionPointMoveDownEnd");
MedsurfDraw.Keyboard.events.remove("released_ArrowLeft", "onPositionPointMoveLeftEnd");
this.collapseAllMenus(new PIXI.InteractionEvent());
if (mode === 'author') {
this.emit("debounceControlUnselectItem", this.parent);
}
};
RectanglePrimitive.prototype._modeSelectItemColor = function () {
this.onOut();
this.image.controlUpdateElements();
this.showItem();
this.emit("pointerover", new PIXI.InteractionEvent());
};
RectanglePrimitive.prototype._removeModeSelectItemColorLine = function (parent, mode) {
this.image.controlSaveColor(this.model.options.lineColor, this.model.options.lineAlpha);
this._removeModeSelectItemColor(parent, mode);
};
RectanglePrimitive.prototype._removeModeSelectItemColorFill = function (parent, mode) {
this.image.controlSaveColor(this.model.options.fillColor, this.model.options.fillAlpha);
this._removeModeSelectItemColor(parent, mode);
};
RectanglePrimitive.prototype._removeModeSelectItemColor = function (parent, mode) {
if (mode !== 'select_child' && !mode.startsWith('select_item_color')) {
this.emit("debounceControlSelectItem");
}
};
RectanglePrimitive.prototype._modeSelectItemNumber = function () {
this.onOut();
this.image.controlUpdateElements();
this.showItem();
this.emit("pointerover", new PIXI.InteractionEvent());
};
RectanglePrimitive.prototype._removeModeSelectItemNumber = function (parent, mode) {
if (mode !== 'select_child' && !mode.startsWith('select_item_number')) {
this.emit("debounceControlSelectItem");
}
};
RectanglePrimitive.prototype._modeBlockedItem = function () {
this._rectangleElement.options.lineAlpha = Design.blocked.lineAlpha;
this._rectangleElement.options.fillAlpha = Design.blocked.fillAlpha;
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._removeModeBlockedItem = function (parent, mode) {
this._rectangleElement.options = Object.assign({}, this.model.options);
if (!mode.startsWith('delete')) {
this.emit("debounceDraw");
}
};
RectanglePrimitive.prototype._modeDrawItem = function () {
};
RectanglePrimitive.prototype._removeModeDrawItem = function () {
this.scaleInteraction.reset();
};
RectanglePrimitive.prototype._modeDrawSelect = function () {
this.interactive = true;
this.cursor = "select";
this._rectangleElement.options.lineColor = Design.positionPoint.lineColorGroup;
this._rectangleElement.options.fillColor = Design.positionPoint.fillColorGroup;
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._removeModeDrawSelect = function (parent, mode) {
this.interactive = false;
this._rectangleElement.options = Object.assign({}, this.model.options);
if (!mode.startsWith('delete')) {
this.emit("debounceDraw");
}
};
RectanglePrimitive.prototype._modeChooseSelect = function () {
this.interactive = true;
this.cursor = "select";
this._rectangleElement.options.lineColor = Design.selftest.lineColorSelect;
this._rectangleElement.options.fillColor = Design.selftest.fillColorSelect;
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._removeModeChooseSelect = function () {
this.interactive = false;
this._rectangleElement.options = Object.assign({}, this.model.options);
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._modeChooseUnselect = function () {
this.interactive = true;
this.cursor = "select";
this._rectangleElement.options.lineColor = Design.selftest.lineColorUnselect;
this._rectangleElement.options.fillColor = Design.selftest.fillColorUnselect;
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._removeModeChooseUnselect = function () {
this.interactive = false;
this._rectangleElement.options = Object.assign({}, this.model.options);
this.emit("debounceDraw");
};
RectanglePrimitive.prototype._modeDelete = function () {
var _this = this;
var parent = this.parent;
if (parent) {
var image = parent.image;
if (parent.model.primitives) {
var index = parent.model.primitives.findIndex(function (primitive) { return primitive.id === _this.model.id; });
if (index > -1) {
if (['delete_draw'].indexOf(this.modeInteraction.lastMode) === -1) {
this.emit("debounceControlUnselectItem", parent);
}
parent.model.primitives.splice(index, 1);
parent.removeChild(this);
parent.emit("debounceDeleteItem", image);
image.deletePrimitive(this.model);
}
}
image.controlHideMenu();
image.controlUpdateElements();
}
this.destroy();
};
RectanglePrimitive.prototype.collapseAllMenus = function (event) {
this._moveToFrontButtonElement.toggleMenu(event, false);
this._verticalMirrorButtonElement.toggleMenu(event, false);
};
RectanglePrimitive.prototype.onButtonEdit = function () {
this.collapseAllMenus(new PIXI.InteractionEvent());
this.image.controlHideMenu();
this.image.editPrimitive(this.model);
};
RectanglePrimitive.prototype.onButtonMoveToFront = function () {
this.model.zIndex++;
this.zIndex = this.model.zIndex;
this.image.sortChildren();
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onButtonMoveToBack = function () {
this.model.zIndex--;
this.zIndex = this.model.zIndex;
this.image.sortChildren();
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onMenuLayer = function (event, visible) {
if (visible) {
this._verticalMirrorButtonElement.toggleMenu(event, false);
}
};
RectanglePrimitive.prototype.onButtonDelete = function (event) {
var _this = this;
this.collapseAllMenus(new PIXI.InteractionEvent());
this.image.controlHideMenu();
setTimeout(function () {
_this.modeInteraction.setMode("delete");
}, 300);
};
RectanglePrimitive.prototype.onButtonDegroup = function (unselectElement) {
if (unselectElement === void 0) { unselectElement = true; }
this.collapseAllMenus(new PIXI.InteractionEvent());
this.image.controlHideMenu();
this.parent.onButtonDegroup(false);
if (unselectElement) {
this.image.unselectLayerGroup();
this.image.selectPrimitive(this.model, this.parent.model);
}
};
RectanglePrimitive.prototype.onButtonVerticalMirror = function () {
if (this.model.rotateWithLine) {
return;
}
var rotation = (Math.round(((this.model.angle || 0) / Math.PI * 180) * 100) / 100) % 360;
if (rotation < 0) {
rotation = 360 + rotation;
}
this.rotation = Math.round(180 - rotation) % 360 * (2 * Math.PI / 360);
this.model.angle = this.rotation;
this.image.controlUpdateElements();
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onButtonHorizontalMirror = function () {
if (this.model.rotateWithLine) {
return;
}
var rotation = (Math.round(((this.model.angle || 0) / Math.PI * 180) * 100) / 100) % 360;
if (rotation < 0) {
rotation = 360 + rotation;
}
this.rotation = Math.round(360 - rotation) % 360 * (2 * Math.PI / 360);
this.model.angle = this.rotation;
this.image.controlUpdateElements();
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onMenuMirror = function (event, visible) {
if (visible) {
this._moveToFrontButtonElement.toggleMenu(event, false);
}
};
RectanglePrimitive.prototype.onButtonDuplicate = function () {
this.collapseAllMenus(new PIXI.InteractionEvent());
this.image.controlHideMenu();
this.parent.onButtonDuplicate();
};
RectanglePrimitive.prototype.onButtonClipboard = function () {
this.collapseAllMenus(new PIXI.InteractionEvent());
this.image.controlHideMenu();
this.parent.onButtonClipboard();
};
RectanglePrimitive.prototype.onColor = function (mode, has, color, colorAlpha) {
if (mode === ColorMode.LINE) {
this.model.options.hasLine = has;
this.model.options.lineColor = color;
this.model.options.lineAlpha = colorAlpha;
this._rectangleElement.options = Object.assign({}, this.model.options);
this._selftestElement.options = Object.assign({}, this.model.options);
this.emit("debounceDraw");
this.image.updatePrimitive(this.model);
}
else if (mode === ColorMode.FILL) {
this.model.options.hasFill = has;
this.model.options.fillColor = color;
this.model.options.fillAlpha = colorAlpha;
this._rectangleElement.options = Object.assign({}, this.model.options);
this._selftestElement.options = Object.assign({}, this.model.options);
this.emit("debounceDraw");
this.image.updatePrimitive(this.model);
}
};
RectanglePrimitive.prototype.onNumber = function (mode, number) {
if (mode === NumberMode.WIDTH) {
this.model.strokeWidth = number / this.imageDimensions.width;
this._rectangleElement.lineWidth = this.model.strokeWidth ? Math.round(this.model.strokeWidth * this.imageDimensions.width * 100) / 100 : undefined;
this.emit("debounceDraw");
this.emit("onBackgroundNumber");
this.image.updatePrimitive(this.model);
}
};
RectanglePrimitive.prototype.onButtonRotateWithLine = function (override) {
this.model.rotateWithLine = override || !this.model.rotateWithLine;
this.onRotateWithLine(new PIXI.InteractionEvent());
if (this.model.rotateWithLine) {
this.parent.on("onRotateWithLine", this.onRotateWithLine, this);
}
else {
this.parent.off("onRotateWithLine", this.onRotateWithLine, this);
}
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onButtonStatic = function (override) {
this.model.isStatic = override || !this.model.isStatic;
this.emit("debounceDraw");
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.controlSelectItem = function () {
this.image.selectPrimitive(this.model, this.parent.model);
this.externControlSelectItem();
};
RectanglePrimitive.prototype.controlUnselectItem = function (parent) {
var image = parent.image;
if (!parent.controlSelectLayerGroup(image)) {
image.externControlSelectImage();
image.unselectPrimitive();
}
};
RectanglePrimitive.prototype.externControlSelectItem = function () {
var parent = this.parent;
this.image.getImageObjects()
.filter(function (imageObject) { return imageObject !== parent; })
.forEach(function (imageObject) {
if (parent.model.selftestItems && parent.model.selftestItems.indexOf(imageObject.name) > -1) {
imageObject.modeInteraction.setMode('choose_select');
}
else if (parent.model.selftestItems && imageObject instanceof MedsurfDraw.LegendCollection) {
var legendRows = imageObject.legendColumns.map(function (lc) { return lc.legendRows; })
.reduce(function (cur, acc) { return __spreadArray(__spreadArray([], cur, true), acc, true); }, [])
.map(function (lr) { return { name: lr.model.id, element: lr }; });
for (var _i = 0, legendRows_1 = legendRows; _i < legendRows_1.length; _i++) {
var legendRow = legendRows_1[_i];
if (parent.model.selftestItems.indexOf(legendRow.name) > -1) {
legendRow.element.modeInteraction.setMode('choose_select');
}
else {
legendRow.element.modeInteraction.setMode('blocket_item');
}
}
}
else {
imageObject.modeInteraction.setMode('blocked_item');
}
});
parent.modeInteraction.setModeItem('select_child');
this.modeInteraction.setModeChildren('select_parent');
this.modeInteraction.setModeItem('select_item');
};
RectanglePrimitive.prototype.controlDrawItem = function () {
this.modeInteraction.setModeChildren('draw_parent');
this.modeInteraction.setModeItem('draw_item');
};
RectanglePrimitive.prototype.startMove = function (event) {
this.parent.moveInteraction.emit("startMove", event);
};
RectanglePrimitive.prototype.onMove = function (event, dX, dY) {
var imageWidth = this.imageDimensions.width;
if (MedsurfDraw.Keyboard.isKeyDown("ControlLeft") || MedsurfDraw.Keyboard.isKeyDown("ControlRight")) {
this.position.x += dX;
this.position.y += dY;
this.model.rectangle.x = this.position.x / imageWidth;
this.model.rectangle.y = this.position.y / imageWidth;
this._selftestElement.selftestPoint = new PIXI.Point(this.parent.x + this.model.rectangle.x * this.imageDimensions.width, this.parent.y + this.model.rectangle.y * this.imageDimensions.width);
this.parent.emit("childMove", event);
}
else {
this.parent.moveInteraction.emit("onMove", event, dX, dY);
}
};
RectanglePrimitive.prototype.endMove = function (event) {
this.parent.moveInteraction.emit("endMove", event);
};
RectanglePrimitive.prototype.endPositionPointMove = function () {
this._selftestElement.selftestPoint = new PIXI.Point(this.parent.x + this.model.rectangle.x * this.imageDimensions.width, this.parent.y + this.model.rectangle.y * this.imageDimensions.width);
};
RectanglePrimitive.prototype.onHover = function () {
this._rectangleElement.options.lineColor = Design.primitive.lineColorHover;
this._rectangleElement.options.fillColor = Design.primitive.fillColorHover;
this.emit("debounceDraw");
};
RectanglePrimitive.prototype.onOut = function () {
this._rectangleElement.options = Object.assign({}, this.model.options);
this.emit("debounceDraw");
};
RectanglePrimitive.prototype.onSelectStart = function (event, preventSelectItem) {
if (preventSelectItem === void 0) { preventSelectItem = false; }
event.stopPropagation();
var lastMode = this.modeInteraction.lastMode;
if (lastMode === 'select_layer_group' || lastMode === 'select_parent') {
this.controlSelectItem();
}
else {
if (!this.parent.controlSelectLayerGroup(this.image) && !preventSelectItem) {
this.controlSelectItem();
}
}
};
RectanglePrimitive.prototype.onSelftest = function () {
this._selftestSelected = true;
this.parent.onSelftest();
this.emit("debounceDraw");
};
RectanglePrimitive.prototype.startScale = function () {
this.interactive = false;
};
RectanglePrimitive.prototype.onScale = function (scaleSide, dX, dY, dW, dH) {
if (this._rectangleElement.rectangle.width + dW < 1) {
return;
}
if (this._rectangleElement.rectangle.height + dH < 1) {
return;
}
var imageWidth = this.imageDimensions.width;
this._rectangleElement.rectangle.width += dW;
this._rectangleElement.rectangle.height += dH;
this.model.rectangle.width = this._rectangleElement.rectangle.width / imageWidth;
this.model.rectangle.height = this._rectangleElement.rectangle.height / imageWidth;
this.draw();
};
RectanglePrimitive.prototype.endScale = function () {
this.interactive = true;
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.startRotate = function () {
this.rotation = (Math.round(this.rotation / Math.PI * 180) * Math.PI / 180);
};
RectanglePrimitive.prototype.onRotate = function (degree) {
this.rotation += degree;
this.model.angle = this.rotation;
this.emit("onBackgroundRotate", degree);
};
RectanglePrimitive.prototype.endRotate = function () {
this.image.updatePrimitive(this.model);
};
RectanglePrimitive.prototype.onRotateWithLine = function (event) {
var parent = this.parent;
var lineStartX = 0;
var lineStartY = 0;
var lineEndX = 0;
var lineEndY = 0;
var lines = parent.getLines();
if (lines.length === 0) {
return;
}
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
var line = lines_1[_i];
if (line.start === parent) {
if (!line.start || !line.end) {
return;
}
lineStartX += line.start.x;
lineStartY += line.start.y;
lineEndX += line.end.x;
lineEndY += line.end.y;
}
else {
if (!line.start || !line.end) {
return;
}
lineStartX += line.end.x;
lineStartY += line.end.y;
lineEndX += line.start.x;
lineEndY += line.start.y;
}
}
lineStartX /= lines.length;
lineStartY /= lines.length;
lineEndX /= lines.length;
lineEndY /= lines.length;
var degree = Math.atan2(lineEndY - lineStartY, lineEndX - lineStartX) - (90 * Math.PI / 180) || 0;
this.rotation = degree + Math.PI / 2;
this.model.angle = this.rotation;
this.emit("onBackgroundRotate", degree);
};
RectanglePrimitive.prototype.onImageZoom = function (scaleX, scaleY) {
this.emit("debounceDraw");
};
RectanglePrimitive.prototype.selftestChanged = function () {
this._selftestElement.isSelftest = this.parent.model.isSelftest;
};
RectanglePrimitive.prototype.getRectangle = function () {
var rect = _super.prototype.getRectangle.call(this);
var position = this.parent.position;
return new PIXI.Rectangle(position.x + rect.x, position.y + rect.y, rect.width, rect.height);
};
Object.defineProperty(RectanglePrimitive.prototype, "moveInteraction", {
get: function () {
return this._moveInteraction;
},
set: function (value) {
this._moveInteraction = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitive.prototype, "scaleInteraction", {
get: function () {
return this._scaleInteraction;
},
set: function (value) {
this._scaleInteraction = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(RectanglePrimitive.prototype, "selectInteraction", {
get: function () {
return this._selectInteraction;
},
set: function (value) {
this._selectInteraction = value;
},
enumerable: false,
configurable: true
});
return RectanglePrimitive;
}(BaseElementContainer));
export { RectanglePrimitive };
//# sourceMappingURL=RectanglePrimitive.js.map