UNPKG

@wcardinal/wcardinal-geditor

Version:

WebGL-based graphic editor, tester and viewer for supervisory systems

1,074 lines 96.2 kB
import { __extends } from "tslib"; import { DApplications, DControllers, DDiagramEditor, DDiagramLayer, DDiagrams, DDiagramSerializedVersion, EShapeBase, EShapeCapabilities, EShapeCapability, EShapeConnectorLine, EShapeGroup, EShapeResourceManagerDeserialization, EShapeResourceManagerSerialization, ESnapperModifierAnchor, isNumber, deserializeAll, EShapeResourceManagerDeserializationMode, DBase } from "@wcardinal/wcardinal-ui"; import { Matrix, Point, Rectangle, utils } from "pixi.js"; import { ECommandComposition } from "../command/e-command-composition"; import { ECommandShapeActionValueAdd } from "../command/e-command-shape-action-value-add"; import { ECommandShapeActionValueBringForward } from "../command/e-command-shape-action-value-bring-forward"; import { ECommandShapeActionValueRemove } from "../command/e-command-shape-action-value-remove"; import { ECommandShapeActionValueReplace } from "../command/e-command-shape-action-value-replace"; import { ECommandShapeActionValueSendBackward } from "../command/e-command-shape-action-value-send-backward"; import { ECommandShapeTreeBringForward } from "../command/e-command-shape-tree-bring-forward"; import { ECommandShapeTreeBringToFront } from "../command/e-command-shape-tree-bring-to-front"; import { ECommandShapeCreate } from "../command/e-command-shape-create"; import { ECommandShapeDelete } from "../command/e-command-shape-delete"; import { ECommandShapePropertyAll } from "../command/e-command-shape-property-all"; import { ECommandShapePropertyCornerOff } from "../command/e-command-shape-property-corner-off"; import { ECommandShapePropertyCursor } from "../command/e-command-shape-property-cursor"; import { ECommandShapePropertyLineHeadMargin } from "../command/e-command-shape-property-line-head-margin"; import { ECommandShapePropertyLineTailMargin } from "../command/e-command-shape-property-line-tail-margin"; import { ECommandShapePropertyFillColor } from "../command/e-command-shape-property-fill-color"; import { ECommandShapePropertyFillEnable } from "../command/e-command-shape-property-fill-enable"; import { ECommandShapePropertyFocusable } from "../command/e-command-shape-property-focusable"; import { ECommandShapePropertyId } from "../command/e-command-shape-property-id"; import { ECommandShapePropertyImage } from "../command/e-command-shape-property-image"; import { ECommandShapePropertyImageFitTo } from "../command/e-command-shape-property-image-fit-to"; import { ECommandShapePropertyInteractive } from "../command/e-command-shape-property-interactive"; import { ECommandShapePropertyLineHeadColor } from "../command/e-command-shape-property-line-head-color"; import { ECommandShapePropertyLineHeadSizeX } from "../command/e-command-shape-property-line-head-size-x"; import { ECommandShapePropertyLineHeadSizeY } from "../command/e-command-shape-property-line-head-size-y"; import { ECommandShapePropertyLineHeadType } from "../command/e-command-shape-property-line-head-type"; import { ECommandShapePropertyLineTailColor } from "../command/e-command-shape-property-line-tail-color"; import { ECommandShapePropertyLineTailSizeX } from "../command/e-command-shape-property-line-tail-size-x"; import { ECommandShapePropertyLineTailSizeY } from "../command/e-command-shape-property-line-tail-size-y"; import { ECommandShapePropertyLineTailType } from "../command/e-command-shape-property-line-tail-type"; import { ECommandShapePropertyPointsStyle } from "../command/e-command-shape-property-points-style"; import { ECommandShapePropertyPosition } from "../command/e-command-shape-property-position"; import { ECommandShapePropertyPositionAndRotate } from "../command/e-command-shape-property-position-and-rotation"; import { ECommandShapePropertyPositionX } from "../command/e-command-shape-property-position-x"; import { ECommandShapePropertyPositionY } from "../command/e-command-shape-property-position-y"; import { ECommandShapePropertyRadius } from "../command/e-command-shape-property-radius"; import { ECommandShapePropertyRotation } from "../command/e-command-shape-property-rotation"; import { ECommandShapePropertyShortcut } from "../command/e-command-shape-property-shortcut"; import { ECommandShapePropertySizeX } from "../command/e-command-shape-property-size-x"; import { ECommandShapePropertySizeY } from "../command/e-command-shape-property-size-y"; import { ECommandShapePropertySkew } from "../command/e-command-shape-property-skew"; import { ECommandShapePropertyStrokeAlign } from "../command/e-command-shape-property-stroke-align"; import { ECommandShapePropertyStrokeColor } from "../command/e-command-shape-property-stroke-color"; import { ECommandShapePropertyStrokeEnable } from "../command/e-command-shape-property-stroke-enable"; import { ECommandShapePropertyStrokeSideOff } from "../command/e-command-shape-property-stroke-side-off"; import { ECommandShapePropertyStrokeStyle } from "../command/e-command-shape-property-stroke-style"; import { ECommandShapePropertyStrokeWidth } from "../command/e-command-shape-property-stroke-width"; import { ECommandShapePropertyTextAlignHorizontal } from "../command/e-command-shape-property-text-align-horizontal"; import { ECommandShapePropertyTextAlignVertical } from "../command/e-command-shape-property-text-align-vertical"; import { ECommandShapePropertyTextClipping } from "../command/e-command-shape-property-text-clipping"; import { ECommandShapePropertyTextColor } from "../command/e-command-shape-property-text-color"; import { ECommandShapePropertyTextDirection } from "../command/e-command-shape-property-text-direction"; import { ECommandShapePropertyTextFamily } from "../command/e-command-shape-property-text-family"; import { ECommandShapePropertyTextOffsetHorizontal } from "../command/e-command-shape-property-text-offset-horizontal"; import { ECommandShapePropertyTextOffsetVertical } from "../command/e-command-shape-property-text-offset-vertical"; import { ECommandShapePropertyTextOutlineColor } from "../command/e-command-shape-property-text-outline-color"; import { ECommandShapePropertyTextOutlineEnable } from "../command/e-command-shape-property-text-outline-enable"; import { ECommandShapePropertyTextOutlineWidth } from "../command/e-command-shape-property-text-outline-width"; import { ECommandShapePropertyTextPaddingHorizontal } from "../command/e-command-shape-property-text-padding-horizontal"; import { ECommandShapePropertyTextPaddingVertical } from "../command/e-command-shape-property-text-padding-vertical"; import { ECommandShapePropertyTextSize } from "../command/e-command-shape-property-text-size"; import { ECommandShapePropertyTextSpacingHorizontal } from "../command/e-command-shape-property-text-spacing-horizontal"; import { ECommandShapePropertyTextSpacingVertical } from "../command/e-command-shape-property-text-spacing-vertical"; import { ECommandShapePropertyTextStyle } from "../command/e-command-shape-property-text-style"; import { ECommandShapePropertyTextValue } from "../command/e-command-shape-property-text-value"; import { ECommandShapePropertyTextWeight } from "../command/e-command-shape-property-text-weight"; import { ECommandShapePropertyTitle } from "../command/e-command-shape-property-title"; import { ECommandShapeReplace } from "../command/e-command-shape-replace"; import { ECommandShapeTreeSendBackward } from "../command/e-command-shape-tree-send-backward"; import { ECommandShapeTreeSendToBack } from "../command/e-command-shape-tree-send-to-back"; import { ECommandShapeDataValueAdd } from "../command/e-command-shape-data-value-add"; import { ECommandShapeDataValueBringForward } from "../command/e-command-shape-data-value-bring-forward"; import { ECommandShapeDataValueRemove } from "../command/e-command-shape-data-value-remove"; import { ECommandShapeDataValueReplace } from "../command/e-command-shape-data-value-replace"; import { ECommandShapeDataValueSendBackward } from "../command/e-command-shape-data-value-send-backward"; import { EToolSelectModifier } from "./e-tool-select-modifier"; import { EToolSelectModifierContainer } from "./e-tool-select-modifier-container"; import { EToolSelectSelectionUpdatedPart } from "./e-tool-select-selection-updated-part"; import { ECommandShapeDataMappingValueAdd } from "../command/e-command-shape-data-mapping-value-add"; import { ECommandShapeDataMappingValueReplace } from "../command/e-command-shape-data-mapping-value-replace"; import { ECommandShapeDataMappingValueRemove } from "../command/e-command-shape-data-mapping-value-remove"; import { ECommandShapeDataMappingValueBringForward } from "../command/e-command-shape-data-mapping-value-bring-forward"; import { ECommandShapeDataMappingValueSendBackward } from "../command/e-command-shape-data-mapping-value-send-backward"; import { ECommandShapePropertyCapabilityLock } from "../command/e-command-shape-property-capability-lock"; import { ECommandShapePropertyCapabilityUnlock } from "../command/e-command-shape-property-capability-unlock"; import { ECommandShapePropertyPositionTop } from "../command/e-command-shape-property-position-top"; import { ECommandShapePropertyPositionLeft } from "../command/e-command-shape-property-position-left"; import { ECommandShapePropertyImageClear } from "../command/e-command-shape-property-image-clear"; import { ECommandShapePropertyCornerOn } from "../command/e-command-shape-property-corner-on"; import { ECommandShapePropertyStrokeSideOn } from "../command/e-command-shape-property-stroke-side-on"; import { ECommandShapeGroup } from "../command/e-command-shape-group"; import { ECommandShapeUngroup } from "../command/e-command-shape-ungroup"; import { ECommandShapePropertyTextSizeDelta } from "../command/e-command-shape-property-text-size-delta"; import { ECommandShapePropertyTextFitting } from "../command/e-command-shape-property-text-fitting"; import { UtilShapeTransforms } from "../util/util-shape-transforms"; import { UtilShapeConnectorTransforms } from "../util/util-shape-connector-transforms"; import { ECommandShapePropertyLineStyle } from "../command/e-command-shape-property-line-style"; import { UtilShapeDeleter } from "../util/util-shape-deleter"; import { UtilShapeSearch } from "../util/util-shape-search"; var initLeft = function (rect) { return rect.x; }; var initCenter = function (rect) { return rect.x + rect.width * 0.5; }; var initRight = function (rect) { return rect.x + rect.width; }; var initTop = function (rect) { return rect.y; }; var initMiddle = function (rect) { return rect.y + rect.height * 0.5; }; var initBottom = function (rect) { return rect.y + rect.height; }; var initWidth = function (rect) { return rect.width; }; var initHeight = function (rect) { return rect.height; }; var initZero = function (rect) { return 0; }; var updateMin = function (valueA, valueB) { return Math.min(valueA, valueB); }; var updateMax = function (valueA, valueB) { return Math.max(valueA, valueB); }; var updateSum = function (valueA, valueB) { return valueA + valueB; }; var finishupIdentity = function (value, size) { return value; }; var finishupAverage = function (value, size) { return value / size; }; var assingX = function (value, point) { point.x = value; }; var assingY = function (value, point) { point.y = value; }; var applyLeft = function (point, diff, scale, shape) { shape.transform.position.x = point.x + diff / scale.x; }; var applyCenter = function (point, diff, scale, shape) { shape.transform.position.x = point.x; }; var applyRight = function (point, diff, scale, shape) { shape.transform.position.x = point.x - diff / scale.x; }; var applyTop = function (point, diff, scale, shape) { shape.transform.position.y = point.y + diff / scale.y; }; var applyMiddle = function (point, diff, scale, shape) { shape.transform.position.y = point.y; }; var applyBottom = function (point, diff, scale, shape) { shape.transform.position.y = point.y - diff / scale.y; }; var EToolSelectSelection = /** @class */ (function (_super) { __extends(EToolSelectSelection, _super); function EToolSelectSelection(options) { var _this = _super.call(this) || this; var diagram = options.diagram; _this._diagram = diagram; var modifier = new EToolSelectModifier(options.modifier); _this._modifier = modifier; var modifierContainer = new EToolSelectModifierContainer(); modifierContainer.addChild(modifier); diagram.on("unset", function (canvas) { if (modifierContainer.parent === canvas) { // Because after this event, a canvas is destroyed. // At that time, all its children also be destroyed. // The modifier container therefore should be removed. canvas.removeChild(modifierContainer); } }); _this._modifierContainer = modifierContainer; _this._originGlobal = new Point(); _this._originLocal = new Point(); _this._rotationAxisGlobal = new Point(); _this._scale = new Point(); _this._scaleAxis0 = new Point(); _this._scaleAxis1 = new Point(); _this._scaleDet = 1; _this._scaleDetInverse = 1; _this._scaleTransform = new Matrix(); _this._scaleTransformInverse = new Matrix(); _this._scaleAnchor = ESnapperModifierAnchor.NONE; _this._shapes = []; _this._shapeBound = new Rectangle(); _this._shapeBoundRect = new Rectangle(); _this._alignPoint = new Point(); _this._alignRectangle = new Rectangle(); _this._shiftPoint1 = new Point(); _this._shiftPoint2 = new Point(); _this._transform = new Matrix(); _this._translateDelta = new Point(); _this._isUpdated = false; _this._updatedParts = EToolSelectSelectionUpdatedPart.NONE; _this._lockCount = 0; return _this; } EToolSelectSelection.prototype.lock = function () { this._lockCount += 1; if (this._lockCount === 1) { this._isUpdated = false; this._updatedParts = EToolSelectSelectionUpdatedPart.NONE; } }; EToolSelectSelection.prototype.unlock = function () { this._lockCount -= 1; if (this._lockCount === 0) { if (this._isUpdated) { this.update(this._updatedParts); } } }; EToolSelectSelection.prototype.update = function (parts) { var parsed = EToolSelectSelectionUpdatedPart.ALL; if (parts != null) { if (isNumber(parts)) { parsed = parts; } else { // eslint-disable-next-line prefer-rest-params parsed = this.toParts(arguments); } } if (this._lockCount <= 0) { this.updateModifier(); this.emit("change", parsed, this); } else { this._isUpdated = true; this._updatedParts |= parsed; } }; EToolSelectSelection.prototype.toParts = function (parts) { if (isNumber(parts)) { return parts; } var result = EToolSelectSelectionUpdatedPart.NONE; for (var i = 0, imax = parts.length; i < imax; ++i) { result |= EToolSelectSelectionUpdatedPart[parts[i]]; } return result; }; EToolSelectSelection.prototype.updateModifier = function () { var diagram = this._diagram; var modifier = this._modifier; if (modifier.isAllowed()) { var shapes = this._shapes; var canvas = diagram.canvas; var modifierContainer = this._modifierContainer; if (canvas == null || shapes.length <= 0) { modifier.visible = false; DApplications.update(diagram); } else if (shapes.length <= 1) { var shape = shapes[0]; if (shape.parent instanceof EShapeBase) { shape.updateTransform(); var internalTransform = shape.transform.internalTransform; var a = internalTransform.a; var b = internalTransform.b; var c = internalTransform.c; var d = internalTransform.d; var pivot = shape.transform.pivot; var modifierPosition = modifier.position; modifierPosition.set(a * pivot.x + c * pivot.y + internalTransform.tx, b * pivot.x + d * pivot.y + internalTransform.ty); var layer = shape.root.parent; if (layer) { modifierContainer.transform.position.copyFrom(layer.transform.position); } else { modifierContainer.transform.position.set(0, 0); } var width = shape.size.x * Math.sqrt(a * a + b * b); var height = shape.size.y * Math.sqrt(c * c + d * d); modifier.width = width; modifier.height = height; modifier.pivot.set(width * 0.5, height * 0.5); var rx = Math.atan2(-c, d); var ry = Math.atan2(+b, a); var skew = (ry - rx) * 0.5; var rotation = (rx + ry) * 0.5; modifier.rotation = rotation; modifier.skew.set(skew, skew); } else { shape.updateTransform(); var internalTransform = shape.transform.internalTransform; var a = internalTransform.a; var b = internalTransform.b; var c = internalTransform.c; var d = internalTransform.d; var pivot = shape.transform.pivot; var modifierPosition = modifier.position; modifierPosition.set(a * pivot.x + c * pivot.y + internalTransform.tx, b * pivot.x + d * pivot.y + internalTransform.ty); var layer = shape.root.parent; if (layer) { modifierContainer.transform.position.copyFrom(layer.transform.position); } else { modifierContainer.transform.position.set(0, 0); } modifier.width = shape.size.x; modifier.height = shape.size.y; modifier.pivot.set(shape.size.x * 0.5, shape.size.y * 0.5); modifier.rotation = shape.transform.rotation; modifier.skew.copyFrom(shape.transform.skew); } modifier.visible = true; modifier.group = EShapeCapabilities.contains(shape, EShapeCapability.CHILDREN) && 0 < shape.children.length; if (modifierContainer.parent !== canvas) { canvas.addChild(modifierContainer); } modifier.update(); DApplications.update(diagram); } else { var bound = this._shapeBound; var tempRect = this._shapeBoundRect; shapes[0].getBoundsInternal(false, bound); for (var i = 1, imax = shapes.length; i < imax; ++i) { var shape = shapes[i]; shape.getBoundsInternal(false, tempRect); bound.enlarge(tempRect); } var layer = shapes[0].root.parent; if (layer) { modifierContainer.transform.position.copyFrom(layer.transform.position); } else { modifierContainer.transform.position.set(0, 0); } modifier.position.set(bound.x, bound.y); modifier.width = bound.width; modifier.height = bound.height; modifier.rotation = 0; modifier.pivot.set(0, 0); modifier.skew.set(0, 0); modifier.visible = true; modifier.group = false; if (modifierContainer.parent !== canvas) { canvas.addChild(modifierContainer); } modifier.update(); DApplications.update(diagram); } } else { modifier.visible = false; DApplications.update(diagram); } }; EToolSelectSelection.prototype.toggle = function (shape) { var shapes = this._shapes; if (shapes.length <= 0) { var root = shape.root; root.selected = true; shapes.push(root); } else { var first = shapes[0]; if (UtilShapeSearch.isParent(shape, first)) { first.selected = false; if (EShapeCapabilities.contains(first, EShapeCapability.CHILDREN)) { var shapeOfParent = UtilShapeSearch.toOfParent(shape, first); shapeOfParent.selected = true; shapes[0] = shapeOfParent; } else { shapes.splice(0, 1); } } else if (first.parent === shape.parent) { if (!shape.selected) { shape.selected = true; shapes.push(shape); } else { shape.selected = false; shapes.splice(shapes.indexOf(shape), 1); } } else { var sharedParent = UtilShapeSearch.toSharedParent(first, shape); if (first.parent === sharedParent) { var shapeOfParent = UtilShapeSearch.toOfParent(shape, sharedParent); if (shapeOfParent.selected) { shapeOfParent.selected = false; shapes.splice(shapes.indexOf(shapeOfParent), 1); } else { shapeOfParent.selected = true; shapes.push(shapeOfParent); } } else { var newLength = 0; for (var i = 0, imax = shapes.length; i < imax; ++i) { var oldShape = shapes[i]; oldShape.selected = false; var newShape = UtilShapeSearch.toOfParent(oldShape, sharedParent); if (!newShape.selected) { newShape.selected = true; shapes[newLength] = newShape; newLength += 1; } } shapes.length = newLength; var shapeOfParent = UtilShapeSearch.toOfParent(shape, sharedParent); if (!shapeOfParent.selected) { shapeOfParent.selected = true; shapes.push(shapeOfParent); } } } } this.update(EToolSelectSelectionUpdatedPart.SELECTION); }; /** * Please note that the specified targets must be root shapes. * * @param targets root shapes to be added */ EToolSelectSelection.prototype.addAll = function (targets) { var shapes = this._shapes; var isChanged = false; // Convert to root shapes if (0 < shapes.length) { var first = shapes[0]; if (first.root !== first) { var oldShapes = shapes.slice(0); shapes.length = 0; for (var i = 0, imax = oldShapes.length; i < imax; ++i) { var oldShape = oldShapes[i]; oldShape.selected = false; var oldShapeRoot = oldShape.root; if (!oldShapeRoot.selected) { oldShapeRoot.selected = true; shapes.push(oldShapeRoot); } } isChanged = true; } } // Add targets for (var i = 0, imax = targets.length; i < imax; ++i) { var target = targets[i]; if (!target.selected) { target.selected = true; shapes.push(target); isChanged = true; } } if (isChanged) { this.update(EToolSelectSelectionUpdatedPart.SELECTION); } return isChanged; }; EToolSelectSelection.prototype.clearAndAddAll = function (targets) { var shapes = this._shapes; for (var i = 0, imax = shapes.length; i < imax; ++i) { shapes[i].selected = false; } shapes.length = 0; for (var i = 0, imax = targets.length; i < imax; ++i) { var target = targets[i]; target.selected = true; shapes.push(target); } this.update(EToolSelectSelectionUpdatedPart.SELECTION); return true; }; EToolSelectSelection.prototype.set = function (target) { var shapes = this._shapes; if (1 < shapes.length) { for (var i = 0, imax = shapes.length; i < imax; ++i) { shapes[i].selected = false; } shapes.length = 0; target.selected = true; shapes.push(target); this.update(EToolSelectSelectionUpdatedPart.SELECTION); return true; } else if (shapes.length === 1) { if (shapes[0] === target) { return false; } else { shapes[0].selected = false; target.selected = true; shapes[0] = target; this.update(EToolSelectSelectionUpdatedPart.SELECTION); return true; } } else { target.selected = true; shapes.push(target); this.update(EToolSelectSelectionUpdatedPart.SELECTION); return true; } }; EToolSelectSelection.prototype.get = function () { return this._shapes; }; EToolSelectSelection.prototype.first = function () { var shapes = this._shapes; return 0 < shapes.length ? shapes[0] : null; }; EToolSelectSelection.prototype.last = function () { var shapes = this._shapes; return 0 < shapes.length ? shapes[shapes.length - 1] : null; }; EToolSelectSelection.prototype.swapLast = function (expectedLast, newLast) { var shapes = this._shapes; if (0 < shapes.length) { var last = shapes[shapes.length - 1]; if (last === expectedLast) { last.selected = false; shapes[shapes.length - 1] = newLast; newLast.selected = true; this.update(EToolSelectSelectionUpdatedPart.TREE | EToolSelectSelectionUpdatedPart.SELECTION); } } }; EToolSelectSelection.prototype.remove = function (target) { var shapes = this._shapes; var index = shapes.indexOf(target); if (0 <= index) { target.selected = false; shapes.splice(index, 1); this.update(EToolSelectSelectionUpdatedPart.TREE | EToolSelectSelectionUpdatedPart.SELECTION); } }; EToolSelectSelection.prototype.contains = function (shape) { return shape.selected; }; EToolSelectSelection.prototype.size = function () { return this._shapes.length; }; EToolSelectSelection.prototype.isEmpty = function () { return this._shapes.length <= 0; }; EToolSelectSelection.prototype.clear = function () { var shapes = this._shapes; if (0 < shapes.length) { for (var i = 0, imax = shapes.length; i < imax; ++i) { shapes[i].selected = false; } this._shapes.length = 0; this.update(EToolSelectSelectionUpdatedPart.SELECTION); return true; } return false; }; EToolSelectSelection.prototype.focus = function () { if (this.isEmpty()) { return false; } // Canvas var diagram = this._diagram; var canvas = diagram.canvas; if (canvas == null) { return false; } // Canvas parent var cparent = canvas.parent; if (!(cparent instanceof DBase)) { return false; } // Center var cw = canvas.width; var ch = canvas.height; var p = cparent.padding; var pl = p.getLeft(); var pt = p.getTop(); var pr = p.getRight(); var pb = p.getBottom(); var sw = Math.max(0, cparent.width - pl - pr); var sh = Math.max(0, cparent.height - pt - pb); var cx = pl + (sw - cw) * 0.5; var cy = pt + (sh - ch) * 0.5; // Offset var modifier = this._modifier; var point = this._alignPoint; point.set(modifier.width * 0.5, modifier.height * 0.5); modifier.toGlobal(point, point, false); cparent.toLocal(point, undefined, point, false); var cposition = canvas.position; var ox = cw * 0.5 - (point.x - cposition.x); var oy = ch * 0.5 - (point.y - cposition.y); // Move diagram.view.moveTo(cx + ox, cy + oy); return true; }; EToolSelectSelection.prototype.prepare = function () { var shapes = this._shapes; if (0 < shapes.length) { for (var i = 0, imax = shapes.length; i < imax; ++i) { var shape = shapes[i]; if (shape instanceof EShapeConnectorLine) { UtilShapeConnectorTransforms.prepare(shape); } else { UtilShapeTransforms.prepare(shape); } } return true; } return false; }; EToolSelectSelection.prototype.prepareTranslateSnap = function () { var diagram = this._diagram; if (diagram instanceof DDiagramEditor) { diagram.snapper.prepareForTranslate(this._modifier); } }; EToolSelectSelection.prototype.prepareRotateSnap = function () { var diagram = this._diagram; if (diagram instanceof DDiagramEditor) { diagram.snapper.prepareForRotate(this._modifier); } }; EToolSelectSelection.prototype.prepareScaleSnap = function () { var diagram = this._diagram; if (diagram instanceof DDiagramEditor) { diagram.snapper.prepareForScale(this._modifier, this._scaleAnchor); } }; EToolSelectSelection.prototype.prepareTranslate = function () { return this.prepare(); }; EToolSelectSelection.prototype.prepareRotate = function (global) { if (this.prepare()) { // Origin var originGlobal = this._originGlobal; var originLocal = this._originLocal; var modifier = this._modifier; originLocal.set(modifier.width * 0.5, modifier.height * 0.5); originGlobal.copyFrom(originLocal); modifier.updateTransform(); modifier.transform.localTransform.apply(originLocal, originLocal); modifier.transform.worldTransform.apply(originGlobal, originGlobal); // Axis if (global == null) { return true; } else { var rotationAxisGlobal = this._rotationAxisGlobal; var vx = global.x - originGlobal.x; var vy = global.y - originGlobal.y; var v = Math.sqrt(vx * vx + vy * vy); if (0.001 < v) { var vi = 1 / v; rotationAxisGlobal.set(vx * vi, vy * vi); return true; } else { this.finalize(); return false; } } } return false; }; EToolSelectSelection.prototype.prepareScale = function (anchor) { if (this.prepare()) { if (this.prepareScaleOriginAndAxes(anchor)) { var modifier = this._modifier; var rotation = modifier.rotation; var skew = modifier.skew; var originLocal = this._originLocal; var scaleTransform = this._scaleTransform; scaleTransform.setTransform(0, 0, 0, 0, 1, 1, rotation, skew.x, skew.y).invert(); scaleTransform.apply(originLocal, originLocal); scaleTransform.translate(-originLocal.x, -originLocal.y); scaleTransform.copyTo(this._scaleTransformInverse).invert(); return true; } else { this.finalize(); return false; } } return false; }; EToolSelectSelection.prototype.prepareScaleOriginAndAxes = function (anchor) { var modifier = this._modifier; modifier.updateTransform(); var localTransform = modifier.transform.localTransform; var worldTransform = modifier.transform.worldTransform; var width = modifier.width; var height = modifier.height; var originGlobal = this._originGlobal; var originLocal = this._originLocal; this._scaleAnchor = anchor; switch (anchor) { case ESnapperModifierAnchor.TOP_LEFT: originLocal.set(width, height); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxes(0, height, width, 0, originGlobal); case ESnapperModifierAnchor.TOP_CENTER: originLocal.set(width * 0.5, height); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxis(width * 0.5, 0, originGlobal); case ESnapperModifierAnchor.TOP_RIGHT: originLocal.set(0, height); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxes(width, height, 0, 0, originGlobal); case ESnapperModifierAnchor.MIDDLE_LEFT: originLocal.set(width, height * 0.5); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxis(0, height * 0.5, originGlobal); case ESnapperModifierAnchor.NONE: originLocal.set(width * 0.5, height * 0.5); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); if (0.001 < Math.abs(width)) { this._scaleAxis0.x = width; } else { return false; } if (0.001 < Math.abs(height)) { this._scaleAxis0.y = height; } else { return false; } return true; case ESnapperModifierAnchor.MIDDLE_RIGHT: originLocal.set(0, height * 0.5); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxis(width, height * 0.5, originGlobal); case ESnapperModifierAnchor.BOTTOM_LEFT: originLocal.set(width, 0); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxes(0, 0, width, height, originGlobal); case ESnapperModifierAnchor.BOTTOM_CENTER: originLocal.set(width * 0.5, 0); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxis(width * 0.5, height, originGlobal); case ESnapperModifierAnchor.BOTTOM_RIGHT: originLocal.set(0, 0); originGlobal.copyFrom(originLocal); localTransform.apply(originLocal, originLocal); worldTransform.apply(originGlobal, originGlobal); return this.prepareScaleAxes(width, 0, 0, height, originGlobal); } return false; }; EToolSelectSelection.prototype.prepareScaleAxis = function (x, y, origin) { var axis = this._scaleAxis0; axis.set(x, y); this._modifier.toGlobal(axis, axis, true); axis.x -= origin.x; axis.y -= origin.y; var v = Math.sqrt(axis.x * axis.x + axis.y * axis.y); if (0.001 < v) { var vi = 1 / v; axis.x *= vi; axis.y *= vi; this._scaleDet = v; this._scaleDetInverse = vi; return true; } return false; }; EToolSelectSelection.prototype.prepareScaleAxes = function (x0, y0, x1, y1, originGlobal) { var modifier = this._modifier; var worldTransform = modifier.transform.worldTransform; // v0 var axis0 = this._scaleAxis0; axis0.set(x0, y0); worldTransform.apply(axis0, axis0); axis0.x -= originGlobal.x; axis0.y -= originGlobal.y; // v1 var axis1 = this._scaleAxis1; axis1.set(x1, y1); worldTransform.apply(axis1, axis1); axis1.x -= originGlobal.x; axis1.y -= originGlobal.y; var det = axis0.x * axis1.y - axis0.y * axis1.x; if (0.001 < Math.abs(det)) { this._scaleDet = det; this._scaleDetInverse = 1 / det; return true; } return false; }; EToolSelectSelection.prototype.finalize = function () { var shapes = this._shapes; if (0 < shapes.length) { for (var i = 0, imax = shapes.length; i < imax; ++i) { var shape = shapes[i]; if (shape instanceof EShapeConnectorLine) { UtilShapeConnectorTransforms.finalize(shape); } else { UtilShapeTransforms.finalize(shape); } } } }; EToolSelectSelection.prototype.saveForTranslate = function () { DControllers.getCommandController().push(new ECommandShapePropertyPosition(this)); }; EToolSelectSelection.prototype.saveForRotate = function () { DControllers.getCommandController().push(new ECommandShapePropertyPositionAndRotate(this)); }; EToolSelectSelection.prototype.saveForScale = function () { DControllers.getCommandController().push(new ECommandShapePropertyAll(this)); }; EToolSelectSelection.prototype.alignLeft = function () { this.align(initLeft, initWidth, updateMin, finishupIdentity, assingX, applyLeft); }; EToolSelectSelection.prototype.alignCenter = function () { this.align(initCenter, initZero, updateSum, finishupAverage, assingX, applyCenter); }; EToolSelectSelection.prototype.alignRight = function () { this.align(initRight, initWidth, updateMax, finishupIdentity, assingX, applyRight); }; EToolSelectSelection.prototype.alignTop = function () { this.align(initTop, initHeight, updateMin, finishupIdentity, assingY, applyTop); }; EToolSelectSelection.prototype.alignMiddle = function () { this.align(initMiddle, initZero, updateSum, finishupAverage, assingY, applyMiddle); }; EToolSelectSelection.prototype.alignBottom = function () { this.align(initBottom, initHeight, updateMax, finishupIdentity, assingY, applyBottom); }; EToolSelectSelection.prototype.align = function (init, initSpace, update, finishup, assing, apply) { var diagram = this._diagram; var canvas = diagram.canvas; var shapes = this._shapes; var shapesLength = shapes.length; if (canvas && 1 <= shapesLength) { var parent_1 = shapes[0].parent; if (parent_1) { var point = this._alignPoint; var rectangle = this._alignRectangle; var isFirst = true; var value = 0; var data = []; for (var i = 0; i < shapesLength; ++i) { var shape = shapes[i]; if (EShapeCapabilities.contains(shape, EShapeCapability.POSITION)) { shape.getBounds(false, rectangle); if (isFirst) { isFirst = false; value = init(rectangle); } else { value = update(value, init(rectangle)); } data.push([initSpace(rectangle), shape]); } } var dataLength = data.length; if (1 <= dataLength) { if (dataLength <= 1) { value = init(canvas.getBounds(false, rectangle)); } value = finishup(value, dataLength); point.set(0, 0); assing(value, point); parent_1.toLocal(point, undefined, point); var scale = canvas.scale; for (var i = 0; i < dataLength; ++i) { var datum = data[i]; apply(point, datum[0] * 0.5, scale, datum[1]); } this.update(EToolSelectSelectionUpdatedPart.PROPERTY); } } } }; EToolSelectSelection.prototype.distributeHorizontally = function () { this.distribute(initCenter, initWidth, assingX, applyLeft); }; EToolSelectSelection.prototype.distributeVertically = function () { this.distribute(initMiddle, initHeight, assingY, applyTop); }; EToolSelectSelection.prototype.distribute = function (init, initSpace, assing, apply) { var diagram = this._diagram; var canvas = diagram.canvas; var shapes = this._shapes; var shapesLength = shapes.length; if (canvas && 1 <= shapesLength) { var parent_2 = shapes[0].parent; if (parent_2) { var point = this._alignPoint; var rectangle = this._alignRectangle; var spaceTotal = 0; var data = []; for (var i = 0; i < shapesLength; ++i) { var shape = shapes[i]; if (EShapeCapabilities.contains(shape, EShapeCapability.POSITION)) { shape.getBounds(false, rectangle); var space = initSpace(rectangle); spaceTotal += space; data.push([init(rectangle), space, shape]); } } var dataLength = data.length; if (2 < dataLength) { data.sort(function (a, b) { return a[0] - b[0]; }); var first = data[0]; var last = data[dataLength - 1]; var spaceLeft = last[0] - first[0] - (spaceTotal - last[1] * 0.5 - first[1] * 0.5); var margin = spaceLeft / (dataLength - 1); point.set(0, 0); assing(first[0], point); parent_2.toLocal(point, undefined, point); var diff = first[1] * 0.5 + margin; var scale = canvas.scale; for (var i = 1, imax = dataLength - 1; i < imax; ++i) { var datum = data[i]; var shape = datum[2]; diff += datum[1] * 0.5; apply(point, diff, scale, shape); diff += datum[1] * 0.5 + margin; } this.update(EToolSelectSelectionUpdatedPart.PROPERTY); } else if (dataLength === 1) { point.set(0, 0); assing(init(canvas.getBounds(false, rectangle)), point); parent_2.toLocal(point, undefined, point); var datum = data[0]; apply(point, 0, canvas.scale, datum[2]); this.update(EToolSelectSelectionUpdatedPart.PROPERTY); } } } }; EToolSelectSelection.prototype.replace = function (shapeFactory) { var shapes = this._shapes; if (0 < shapes.length) { var parent_3 = shapes[0].parent; if (parent_3) { DControllers.getCommandController().push(new ECommandShapeReplace(parent_3, shapeFactory, this)); } } }; EToolSelectSelection.prototype.group = function () { var shapes = this._shapes; if (2 <= shapes.length) { var parent_4 = shapes[0].parent; if (parent_4) { DControllers.getCommandController().push(new ECommandShapeGroup(parent_4, this)); } } }; EToolSelectSelection.prototype.hasUngroupable = function (shapes) { for (var i = shapes.length - 1; 0 <= i; --i) { if (this.isUngroupable(shapes[i])) { return true; } } return false; }; EToolSelectSelection.prototype.isUngroupable = function (shape) { return (shape instanceof EShapeGroup && EShapeCapabilities.contains(shape, EShapeCapability.CHILDREN) && EShapeCapabilities.contains(shape, EShapeCapability.UNGROUPING)); }; EToolSelectSelection.prototype.ungroup = function () { var shapes = this._shapes; if (this.hasUngroupable(shapes)) { var parent_5 = shapes[0].parent; if (parent_5) { DControllers.getCommandController().push(new ECommandShapeUngroup(parent_5, this)); } } }; EToolSelectSelection.prototype.setFill = function (color, alpha) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyFillColor(this, [color, alpha])); } }; EToolSelectSelection.prototype.setFillEnabled = function (enable) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyFillEnable(this, enable)); } }; EToolSelectSelection.prototype.setStroke = function (color, alpha) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeColor(this, [color, alpha])); } }; EToolSelectSelection.prototype.setStrokeWidth = function (width) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeWidth(this, width)); } }; EToolSelectSelection.prototype.setStrokeAlign = function (align) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeAlign(this, align)); } }; EToolSelectSelection.prototype.setStrokeSide = function (side, isOn) { var shapes = this._shapes; if (0 < shapes.length) { if (isOn) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeSideOn(this, side)); } else { DControllers.getCommandController().push(new ECommandShapePropertyStrokeSideOff(this, side)); } } }; EToolSelectSelection.prototype.setStrokeStyle = function (add, remove) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeStyle(this, add, remove)); } }; EToolSelectSelection.prototype.setStrokeEnabled = function (enable) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyStrokeEnable(this, enable)); } }; EToolSelectSelection.prototype.setLineStyle = function (add, remove) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommandController().push(new ECommandShapePropertyLineStyle(this, add, remove)); } }; EToolSelectSelection.prototype.setLineTailType = function (type) { var shapes = this._shapes; if (0 < shapes.length) { DControllers.getCommand