@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
77 lines • 3.4 kB
JavaScript
import { __extends } from "tslib";
import { EShapeCapability, EShapeLockPart, EShapePointsFormatters, EShapePointsStyle, toPointsBoundary } from "@wcardinal/wcardinal-ui";
import { EToolShapeEditLineBase } from "./e-tool-shape-edit-line-base";
import { Point } from "pixi.js";
var EToolShapeEditLine = /** @class */ (function (_super) {
__extends(EToolShapeEditLine, _super);
function EToolShapeEditLine() {
return _super !== null && _super.apply(this, arguments) || this;
}
EToolShapeEditLine.prototype.onShapeSet = function (shape) {
var points = shape.points;
if (points) {
shape.updateTransform();
this._points = this.toPoints(points, this.toTransform(shape));
this._pointsStyle = this.toPointsStyle(points);
this._formatter = this.toFormatter(points, this._pointsStyle);
}
else {
this._points = [];
this._pointsStyle = EShapePointsStyle.NONE;
this._formatter = undefined;
}
this.reshape();
var canvas = this._diagram.canvas;
if (canvas) {
canvas.addChild(this);
}
};
EToolShapeEditLine.prototype.toPoints = function (points, transform) {
var result = [];
var values = points.values;
for (var i = 0, imax = values.length; i < imax; i += 2) {
var point = new Point(values[i], values[i + 1]);
result.push(transform.apply(point, point));
}
return result;
};
EToolShapeEditLine.prototype.toPointsStyle = function (points) {
return points.style;
};
EToolShapeEditLine.prototype.toFormatter = function (points, pointsStyle) {
var _a, _b;
return (_a = points.formatter) !== null && _a !== void 0 ? _a : (_b = EShapePointsFormatters.find(pointsStyle)) === null || _b === void 0 ? void 0 : _b.formatter;
};
EToolShapeEditLine.prototype.toCapability = function (shape) {
return EShapeCapability.LINE_TAIL | EShapeCapability.LINE_HEAD;
};
EToolShapeEditLine.prototype.newShape = function (values, segments, style, oldShape) {
var boundary = toPointsBoundary(values, [0, 0, 0, 0]);
var cx = (boundary[2] + boundary[0]) * 0.5;
var cy = (boundary[3] + boundary[1]) * 0.5;
var sx = boundary[2] - boundary[0];
var sy = boundary[3] - boundary[1];
var result = oldShape.clone();
var transform = result.transform;
var transformPosition = transform.position;
var localTransform = oldShape.transform.localTransform;
var x = localTransform.a * cx + localTransform.c * cy + transformPosition.x;
var y = localTransform.b * cx + localTransform.d * cy + transformPosition.y;
var newValues = [];
for (var i = 0, imax = values.length; i < imax; i += 2) {
newValues.push(values[i] - cx, values[i + 1] - cy);
}
result.lock(EShapeLockPart.UPLOADED);
result.transform.position.set(x, y);
result.size.set(sx, sy);
var points = result.points;
if (points) {
points.set(newValues, segments, style);
}
result.unlock(EShapeLockPart.UPLOADED, true);
return result;
};
return EToolShapeEditLine;
}(EToolShapeEditLineBase));
export { EToolShapeEditLine };
//# sourceMappingURL=e-tool-shape-edit-line.js.map