@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
86 lines • 3.03 kB
JavaScript
import { __extends } from "tslib";
import { DCommandBase } from "@wcardinal/wcardinal-ui";
var ECommandShapeReplaceOne = /** @class */ (function (_super) {
__extends(ECommandShapeReplaceOne, _super);
function ECommandShapeReplaceOne(newShape, oldShape, parent, selection) {
var _this = _super.call(this) || this;
_this._parent = parent;
_this._newShape = newShape;
_this._oldShape = oldShape;
_this._selection = selection;
_this._index = parent.children.indexOf(oldShape);
newShape.reference += 1;
oldShape.reference += 1;
return _this;
}
Object.defineProperty(ECommandShapeReplaceOne.prototype, "parent", {
get: function () {
return this._parent;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeReplaceOne.prototype, "oldShape", {
get: function () {
return this._oldShape;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeReplaceOne.prototype, "newShape", {
get: function () {
return this._newShape;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeReplaceOne.prototype, "index", {
get: function () {
return this._index;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ECommandShapeReplaceOne.prototype, "selection", {
get: function () {
return this._selection;
},
enumerable: false,
configurable: true
});
ECommandShapeReplaceOne.prototype.execute = function () {
this._oldShape.detach();
this._newShape.attach(this._parent, this._index);
this._selection.swapLast(this._oldShape, this._newShape);
return true;
};
ECommandShapeReplaceOne.prototype.redo = function () {
this._newShape.attach(this._parent, this._index);
this._oldShape.detach();
this._selection.swapLast(this._oldShape, this._newShape);
return true;
};
ECommandShapeReplaceOne.prototype.undo = function () {
this._newShape.detach();
this._oldShape.attach(this._parent, this._index);
this._selection.swapLast(this._newShape, this._oldShape);
return true;
};
ECommandShapeReplaceOne.prototype.destroy = function () {
// Destroy new shapes
var newShape = this._newShape;
newShape.reference -= 1;
if (newShape.parent == null && newShape.reference <= 0) {
newShape.destroy();
}
// Destroy old shapes
var oldShape = this._oldShape;
oldShape.reference -= 1;
if (oldShape.parent == null && oldShape.reference <= 0) {
oldShape.destroy();
}
};
return ECommandShapeReplaceOne;
}(DCommandBase));
export { ECommandShapeReplaceOne };
//# sourceMappingURL=e-command-shape-replace-one.js.map