UNPKG

@wcardinal/wcardinal-geditor

Version:

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

168 lines 6.43 kB
import { __extends } from "tslib"; import { DCommandBase, EShapeCapabilities, EShapeCapability, EShapeGroup, EShapeLockPart } from "@wcardinal/wcardinal-ui"; import { EToolSelectSelectionUpdatedPart } from "../tool/e-tool-select-selection-updated-part"; var ECommandShapeReplace = /** @class */ (function (_super) { __extends(ECommandShapeReplace, _super); function ECommandShapeReplace(parent, factory, selection) { var _this = _super.call(this) || this; _this._parent = parent; _this._factory = factory; _this._selection = selection; _this._newShapes = []; _this._oldShapes = []; _this._indices = []; return _this; } Object.defineProperty(ECommandShapeReplace.prototype, "parent", { get: function () { return this._parent; }, enumerable: false, configurable: true }); Object.defineProperty(ECommandShapeReplace.prototype, "oldShapes", { get: function () { return this._oldShapes; }, enumerable: false, configurable: true }); Object.defineProperty(ECommandShapeReplace.prototype, "newShapes", { get: function () { return this._newShapes; }, enumerable: false, configurable: true }); Object.defineProperty(ECommandShapeReplace.prototype, "indices", { get: function () { return this._indices; }, enumerable: false, configurable: true }); Object.defineProperty(ECommandShapeReplace.prototype, "selection", { get: function () { return this._selection; }, enumerable: false, configurable: true }); ECommandShapeReplace.prototype.execute = function () { var parent = this._parent; var indices = this._indices; var newShapes = this._newShapes; var oldShapes = this._oldShapes; var children = parent.children; var factory = this._factory; for (var i = 0, imax = children.length; i < imax; ++i) { var child = children[i]; if (child.selected) { var newShape = void 0; if (EShapeCapabilities.contains(child, EShapeCapability.REPLACING)) { if (child instanceof EShapeGroup) { var pivot = child.transform.pivot; var pivotX = pivot.x; var pivotY = pivot.y; if (pivotX !== 0 || pivotY !== 0) { child.lock(EShapeLockPart.TRANSFORM); pivot.set(0, 0); newShape = factory(child) || child; pivot.set(pivotX, pivotY); child.unlock(EShapeLockPart.TRANSFORM, false); } else { newShape = factory(child) || child; } } else { newShape = factory(child) || child; } if (newShape !== child) { child.reference += 1; newShape.reference += 1; child.detach(); newShape.attach(parent, i); } } else { newShape = child; } indices.push(i); newShapes.push(newShape); oldShapes.push(child); } } var selection = this._selection; selection.lock(); selection.clearAndAddAll(newShapes); selection.update(EToolSelectSelectionUpdatedPart.TREE | EToolSelectSelectionUpdatedPart.SELECTION); selection.unlock(); return true; }; ECommandShapeReplace.prototype.redo = function () { var parent = this._parent; var indices = this._indices; var oldShapes = this._oldShapes; var newShapes = this._newShapes; for (var i = 0, imax = newShapes.length; i < imax; ++i) { var oldShape = oldShapes[i]; var newShape = newShapes[i]; if (oldShape !== newShape) { oldShape.detach(); newShape.attach(parent, indices[i]); } } var selection = this._selection; selection.lock(); selection.clearAndAddAll(newShapes); selection.update(EToolSelectSelectionUpdatedPart.TREE | EToolSelectSelectionUpdatedPart.SELECTION); selection.unlock(); return true; }; ECommandShapeReplace.prototype.undo = function () { var parent = this._parent; var indices = this._indices; var oldShapes = this._oldShapes; var newShapes = this._newShapes; for (var i = 0, imax = newShapes.length; i < imax; ++i) { var oldShape = oldShapes[i]; var newShape = newShapes[i]; if (oldShape !== newShape) { newShape.detach(); oldShape.attach(parent, indices[i]); } } var selection = this._selection; selection.lock(); selection.clearAndAddAll(oldShapes); selection.update(EToolSelectSelectionUpdatedPart.TREE | EToolSelectSelectionUpdatedPart.SELECTION); selection.unlock(); return true; }; ECommandShapeReplace.prototype.destroy = function () { // Destroy Shapes var oldShapes = this._oldShapes; var newShapes = this._newShapes; for (var i = 0, imax = newShapes.length; i < imax; ++i) { var oldShape = oldShapes[i]; var newShape = newShapes[i]; if (oldShape !== newShape) { newShape.reference -= 1; if (newShape.parent == null && newShape.reference <= 0) { newShape.destroy(); } oldShape.reference -= 1; if (oldShape.parent == null && oldShape.reference <= 0) { oldShape.destroy(); } } } oldShapes.length = 0; newShapes.length = 0; this.indices.length = 0; }; return ECommandShapeReplace; }(DCommandBase)); export { ECommandShapeReplace }; //# sourceMappingURL=e-command-shape-replace.js.map