gd-canvas
Version:
This set of libraries was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.0 and no dependencies accept gd-tree (it has jquery and jstree) and gd-graph (it has jquery and chart.js).
1,011 lines (974 loc) • 289 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('gd-canvas-custom-types'), require('gd-common'), require('gd-tooltip'), require('@angular/common'), require('gd-window')) :
typeof define === 'function' && define.amd ? define('gd-canvas', ['exports', '@angular/core', 'gd-canvas-custom-types', 'gd-common', 'gd-tooltip', '@angular/common', 'gd-window'], factory) :
(global = global || self, factory(global['gd-canvas'] = {}, global.ng.core, global['gd-canvas-custom-types'], global['gd-common'], global['gd-tooltip'], global.ng.common, global['gd-window']));
}(this, (function (exports, core, gdCanvasCustomTypes, gdCommon, gdTooltip, common, gdWindow) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
var GDCanvasService = /** @class */ (function () {
function GDCanvasService() {
this.showContextmenu$ = new core.EventEmitter();
this.focusedMove$ = new core.EventEmitter();
this.redrawRefChildren$ = new core.EventEmitter();
this.selectedChanged$ = new core.EventEmitter();
this.canvasIsReady$ = new core.EventEmitter();
this.canvasInfo$ = new core.EventEmitter();
this.customLayerRequest$ = new core.EventEmitter();
this.shapeChangedParent$ = new core.EventEmitter();
}
GDCanvasService.prototype.SelectedChanged = function (arg) {
this.selectedChanged$.emit(arg);
};
GDCanvasService.prototype.ShowContextmenu = function (arg) {
this.showContextmenu$.emit(arg);
};
GDCanvasService.prototype.CustomLayerRequest = function (arg) {
this.customLayerRequest$.emit(arg);
};
GDCanvasService.prototype.CanvasIsReady = function (arg) {
this.canvasIsReady$.emit(arg);
};
GDCanvasService.prototype.CanvasInfo = function (info) {
this.canvasInfo$.emit(info);
};
GDCanvasService.prototype.FocusedMove = function (offset) {
this.focusedMove$.emit(offset);
};
GDCanvasService.prototype.RedrawRefChildren = function () {
this.redrawRefChildren$.emit();
};
GDCanvasService.prototype.ShapeChangedParent = function (shape) {
this.shapeChangedParent$.emit(shape);
};
GDCanvasService.ɵfac = function GDCanvasService_Factory(t) { return new (t || GDCanvasService)(); };
GDCanvasService.ɵprov = core["ɵɵdefineInjectable"]({ token: GDCanvasService, factory: GDCanvasService.ɵfac, providedIn: 'root' });
return GDCanvasService;
}());
/*@__PURE__*/ (function () { core["ɵsetClassMetadata"](GDCanvasService, [{
type: core.Injectable,
args: [{
providedIn: 'root'
}]
}], function () { return []; }, null); })();
(function (GondolaTypes) {
GondolaTypes[GondolaTypes["regular"] = 1] = "regular";
GondolaTypes[GondolaTypes["wall"] = 2] = "wall";
})(exports.GondolaTypes || (exports.GondolaTypes = {}));
var ShapeWithDistance = /** @class */ (function () {
function ShapeWithDistance(s, d) {
this.shape = s;
this.distance = d;
}
return ShapeWithDistance;
}());
(function (DefaultActions) {
DefaultActions[DefaultActions["none"] = 0] = "none";
DefaultActions[DefaultActions["move"] = 1] = "move";
DefaultActions[DefaultActions["moveActivePoint"] = 2] = "moveActivePoint";
DefaultActions[DefaultActions["moveActiveLine"] = 3] = "moveActiveLine";
DefaultActions[DefaultActions["rotate"] = 4] = "rotate";
DefaultActions[DefaultActions["resize"] = 5] = "resize";
DefaultActions[DefaultActions["select"] = 6] = "select";
DefaultActions[DefaultActions["selectShapesInOrder"] = 7] = "selectShapesInOrder";
DefaultActions[DefaultActions["selectShapes"] = 8] = "selectShapes";
DefaultActions[DefaultActions["pan"] = 9] = "pan";
DefaultActions[DefaultActions["scale"] = 10] = "scale";
DefaultActions[DefaultActions["dnd"] = 11] = "dnd";
// addRegularGondola = 12,
// addWallGondola = 13,
DefaultActions[DefaultActions["addShape"] = 14] = "addShape";
DefaultActions[DefaultActions["addPolygon"] = 15] = "addPolygon";
// addArea = 16
DefaultActions[DefaultActions["edit"] = 17] = "edit";
DefaultActions[DefaultActions["deletePolylinePoint"] = 18] = "deletePolylinePoint";
DefaultActions[DefaultActions["addPolylinePoint"] = 19] = "addPolylinePoint";
})(exports.DefaultActions || (exports.DefaultActions = {}));
(function (State) {
State[State["unchanged"] = 0] = "unchanged";
State[State["added"] = 1] = "added";
State[State["changed"] = 2] = "changed";
State[State["deleted"] = 3] = "deleted";
})(exports.State || (exports.State = {}));
(function (DefaultTypes) {
// add to the end
DefaultTypes[DefaultTypes["none"] = 0] = "none";
DefaultTypes[DefaultTypes["drawing"] = 1] = "drawing";
DefaultTypes[DefaultTypes["fixture"] = 2] = "fixture";
DefaultTypes[DefaultTypes["fixtureContainer"] = 3] = "fixtureContainer";
DefaultTypes[DefaultTypes["fixtureProduct"] = 4] = "fixtureProduct";
//gondola = 5,
DefaultTypes[DefaultTypes["container"] = 6] = "container";
DefaultTypes[DefaultTypes["polygon"] = 7] = "polygon";
DefaultTypes[DefaultTypes["shape"] = 8] = "shape";
DefaultTypes[DefaultTypes["text"] = 9] = "text";
DefaultTypes[DefaultTypes["segment"] = 10] = "segment";
DefaultTypes[DefaultTypes["polyline"] = 11] = "polyline";
DefaultTypes[DefaultTypes["arc"] = 12] = "arc";
DefaultTypes[DefaultTypes["dimension"] = 13] = "dimension";
DefaultTypes[DefaultTypes["callout"] = 14] = "callout";
// shapeContainer = 15,
DefaultTypes[DefaultTypes["reference"] = 16] = "reference";
DefaultTypes[DefaultTypes["block"] = 17] = "block";
DefaultTypes[DefaultTypes["gondolaWall"] = 18] = "gondolaWall";
})(exports.DefaultTypes || (exports.DefaultTypes = {}));
var ShapeOver = /** @class */ (function () {
function ShapeOver() {
}
return ShapeOver;
}());
(function (ShapeTypes) {
ShapeTypes[ShapeTypes["none"] = 0] = "none";
ShapeTypes[ShapeTypes["Rect"] = 1] = "Rect";
ShapeTypes[ShapeTypes["Ellipse"] = 2] = "Ellipse";
})(exports.ShapeTypes || (exports.ShapeTypes = {}));
(function (TextLayout) {
TextLayout[TextLayout["none"] = 0] = "none";
TextLayout[TextLayout["Above"] = 1] = "Above";
TextLayout[TextLayout["Inside"] = 2] = "Inside";
TextLayout[TextLayout["Bellow"] = 3] = "Bellow";
})(exports.TextLayout || (exports.TextLayout = {}));
(function (LineStyles) {
LineStyles[LineStyles["none"] = 0] = "none";
LineStyles[LineStyles["Solid"] = 1] = "Solid";
LineStyles[LineStyles["Dashed"] = 2] = "Dashed";
LineStyles[LineStyles["Dotted"] = 3] = "Dotted";
})(exports.LineStyles || (exports.LineStyles = {}));
(function (LineTypes) {
LineTypes[LineTypes["none"] = 0] = "none";
LineTypes[LineTypes["Line"] = 1] = "Line";
LineTypes[LineTypes["Arc"] = 2] = "Arc";
})(exports.LineTypes || (exports.LineTypes = {}));
var Types = __assign(__assign({}, exports.DefaultTypes), gdCanvasCustomTypes.CustomTypes);
var Actions = __assign(__assign({}, exports.DefaultActions), gdCanvasCustomTypes.CustomActions);
var Tools = /** @class */ (function () {
function Tools() {
}
Tools.prototype.Rotate = function (point, center, angle) {
var origin = new gdCommon.Point(point.x - center.x, point.y - center.y);
if (angle === 0) {
return origin;
}
var radians = angle * Math.PI / 180.0;
var nx = origin.x * Math.cos(radians) - origin.y * Math.sin(radians);
var ny = origin.x * Math.sin(radians) + origin.y * Math.cos(radians);
return new gdCommon.Point(nx, ny);
};
Tools.prototype.Normal = function (point, start, end) {
if (end.x === start.x)
return new gdCommon.Point(start.x, point.y);
if (end.y === start.y)
return new gdCommon.Point(point.x, start.y);
var k1 = (end.y - start.y) / (end.x - start.x);
var k2 = (start.x - end.x) / (end.y - start.y);
var b1 = start.y - k1 * start.x;
var b2 = point.y - k2 * point.x;
var x = (b2 - b1) / (k1 - k2);
var y = k1 * x + b1;
return new gdCommon.Point(x, y);
};
Tools.prototype.DistanceTo = function (point, start, end) {
return Math.abs((end.y - start.y) * point.x - (end.x - start.x) * point.y + end.x * start.y - end.y * start.x) /
Math.sqrt(Math.pow(end.y - start.y, 2) + Math.pow(end.x - start.x, 2));
};
Tools.prototype.Intersect_OLD = function (a, b, c, d) {
/*
(Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy)
r = ----------------------------- (eqn 1)
(Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
*/
var p = this.Intersection(a, b, c, d);
return (p.x !== 0 && p.y !== 0);
};
Tools.prototype.Intersect = function (a, b, c, d) {
return this.doIntersect(a, b, c, d);
};
// Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
Tools.prototype.onSegment = function (p, q, r) {
if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&
q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))
return true;
return false;
};
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
Tools.prototype.orientation = function (p, q, r) {
// See https://www.geeksforgeeks.org/orientation-3-ordered-points/
// for details of below formula.
var val = (q.y - p.y) * (r.x - q.x) -
(q.x - p.x) * (r.y - q.y);
if (val === 0)
return 0; // colinear
return (val > 0 ? 1 : 2); // clock or counterclock wise
};
// The main function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
Tools.prototype.doIntersect = function (p1, q1, p2, q2) {
// Find the four orientations needed for general and
// special cases
var o1 = this.orientation(p1, q1, p2);
var o2 = this.orientation(p1, q1, q2);
var o3 = this.orientation(p2, q2, p1);
var o4 = this.orientation(p2, q2, q1);
// General case
if (o1 !== o2 && o3 !== o4)
return true;
// Special Cases
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
if (o1 === 0 && this.onSegment(p1, p2, q1))
return true;
// p1, q1 and q2 are colinear and q2 lies on segment p1q1
if (o2 === 0 && this.onSegment(p1, q2, q1))
return true;
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
if (o3 === 0 && this.onSegment(p2, p1, q2))
return true;
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
if (o4 === 0 && this.onSegment(p2, q1, q2))
return true;
return false; // Doesn't fall in any of the above cases
};
Tools.prototype.Intersection = function (p1, p2, p3, p4) {
// calculate differences
var xD1 = p2.x - p1.x;
var yD1 = p2.y - p1.y;
var xD2 = p4.x - p3.x;
var yD2 = p4.y - p3.y;
var xD3 = p1.x - p3.x;
var yD3 = p1.y - p3.y;
// calculate the lengths of the two lines
var Len1 = Math.sqrt(xD1 * xD1 + yD1 * yD1);
var Len2 = Math.sqrt(xD2 * xD2 + yD2 * yD2);
// calculate angle between the two lines.
var dot = (xD1 * xD2 + yD1 * yD2); // dot product
var deg = dot / (Len1 * Len2);
// if Math.Abs(angle)==1 then the lines are parallell,
// so no intersection is possible
if (Math.abs(deg) === 1)
return new gdCommon.Point(0, 0);
// find intersection Pt between two lines
var pt = new gdCommon.Point(0, 0);
var div = yD2 * xD1 - xD2 * yD1;
var ua = (xD2 * yD3 - yD2 * xD3) / div;
var ub = (xD1 * yD3 - yD1 * xD3) / div;
pt.x = p1.x + ua * xD1;
pt.y = p1.y + ua * yD1;
// calculate the combined length of the two segments
// between Pt-p1 and Pt-p2
xD1 = pt.x - p1.x;
yD1 = pt.y - p1.y;
xD2 = pt.x - p2.x;
yD2 = pt.y - p2.y;
var len1 = Math.sqrt(xD1 * xD1 + yD1 * yD1) + Math.sqrt(xD2 * xD2 + yD2 * yD2);
// calculate the combined length of the two segments
// between Pt-p3 and Pt-p4
xD1 = pt.x - p3.x;
yD1 = pt.y - p3.y;
xD2 = pt.x - p4.x;
yD2 = pt.y - p4.y;
var len2 = Math.sqrt(xD1 * xD1 + yD1 * yD1) + Math.sqrt(xD2 * xD2 + yD2 * yD2);
var diff1 = Math.abs(Len1 - len1);
var diff2 = Math.abs(Len2 - len2);
if (diff1 > 0.01 || diff2 > 0.01)
return new gdCommon.Point(0, 0);
return pt;
};
Tools.prototype.PointSide = function (point, start, end) {
var D = (point.x - start.x) * (end.y - start.y) - (point.y - start.y) * (end.x - start.x);
var result = (D === 0 ? 'INSIDE' : (D > 0 ? 'RIGHT' : 'LEFT'));
return result;
};
Tools.prototype.RoundRect = function (ctx, x, y, width, height, radius, fill, stroke) {
if (typeof stroke === 'undefined') {
stroke = true;
}
if (typeof radius === 'undefined') {
radius = 5;
}
// --width;
// --height;
// x -= 0.5;
// y -= 0.5;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
if (fill)
ctx.fill();
if (stroke)
ctx.stroke();
};
Tools.prototype.MeasureText = function (text, font, style) {
var div = document.createElement('div');
document.body.appendChild(div);
div.style.font = font;
div.style.position = 'absolute';
div.style.left = '-1000';
div.style.top = '-1000';
div.style.fontStyle = style;
div.innerHTML = text;
var result = {
width: div.clientWidth,
height: div.clientHeight
};
document.body.removeChild(div);
div = null;
return result;
};
return Tools;
}());
var Selector = /** @class */ (function () {
function Selector(canvas, service) {
var _this = this;
this.service = service;
this.canvas = canvas;
this.selected = new Array();
this.focused = null;
this.tools = new Tools();
service.focusedMove$.subscribe(function (offset) { return _this.OnFocusedMove(offset); });
}
Object.defineProperty(Selector.prototype, "StartX", {
get: function () { return this.startX; },
set: function (x) { this.startX = x; this.rect = null; },
enumerable: true,
configurable: true
});
Object.defineProperty(Selector.prototype, "StartY", {
get: function () { return this.startY; },
set: function (y) { this.startY = y; this.rect = null; },
enumerable: true,
configurable: true
});
Object.defineProperty(Selector.prototype, "EndX", {
get: function () { return this.endX; },
set: function (x) { this.endX = x; this.rect = null; },
enumerable: true,
configurable: true
});
Object.defineProperty(Selector.prototype, "EndY", {
get: function () { return this.endY; },
set: function (y) { this.endY = y; this.rect = null; },
enumerable: true,
configurable: true
});
Selector.prototype.OnFocusedMove = function (offset) {
for (var i = 0; i < this.selected.length; ++i) {
if (this.selected[i].IsFocused)
continue;
if (this.selected[i].ParentID !== null)
continue;
this.selected[i].MoveOffset(offset.x, offset.y);
}
};
Selector.prototype.GetPoints = function () {
var x = Math.min(this.startX, this.endX);
var y = Math.min(this.startY, this.endY);
var w = Math.abs(this.startX - this.endX);
var h = Math.abs(this.startY - this.endY);
var points = [
{ x: x, y: y },
{ x: x + w, y: y },
{ x: x + w, y: y + h },
{ x: x, y: y + h },
{ x: x, y: y }
];
return points;
};
Selector.prototype.Refresh = function () {
if (this.rect !== null)
return;
var x = Math.min(this.startX, this.endX);
var y = Math.min(this.startY, this.endY);
var w = Math.abs(this.startX - this.endX);
var h = Math.abs(this.startY - this.endY);
this.rect = new gdCommon.Rect(x, y, w, h);
};
Selector.prototype.Add = function (object) {
if (this.rect === null)
return false;
if (object === undefined)
return false;
if (object.IsSelected)
return false;
var flag = true;
var x = this.rect.x / this.canvas.scale - this.canvas.canvasOffsetX;
var y = this.rect.y / this.canvas.scale - this.canvas.canvasOffsetY;
var modelRect = new gdCommon.Rect(x, y, this.rect.w / this.canvas.scale, this.rect.h / this.canvas.scale);
var points = object.GetPolygon();
for (var j = 0; j < points.length; ++j) {
if (!modelRect.IsContains(points[j])) {
flag = false;
break;
}
}
if (!flag)
return false;
if (this.selected.length === 0) {
this.focused = object;
object.IsFocused = true;
}
this.selected.push(object);
object.IsSelected = true;
return true;
};
Selector.prototype.ClearSelection = function () {
this.selected = new Array();
if (this.focused === null)
return;
this.focused.IsFocused = false;
this.focused.activePoint = -1;
this.focused.activeLine = -1;
this.focused = null;
};
Selector.prototype.Select = function (point, isRightClick) {
var toRedraw = [];
var object = this.canvas.GetObjectClicked(point);
if (object === undefined) {
if (this.focused !== null) {
var res = this.UnSelect();
this.canvas.DRAW(res);
this.service.SelectedChanged(null);
}
return false;
}
if (!this.canvas.isAltKey) {
if (object.type === Types.polyline) {
}
if (object.type === Types.polygon) {
if (object.Text.IsFocused) {
this.selected.push(object);
}
else {
if (!object.IsSelected) {
this.UnSelect();
}
if (object.activeLine !== -1) {
this.selected.push(object);
}
}
}
else {
if (object.IsRef) {
if (object.IsSelected) {
object.Reference.IsVisible = !object.Reference.IsVisible;
if (object.Reference.IsRef) {
object.Reference.Reference.IsVisible = object.Reference.IsVisible; //?????????????????????
}
}
else {
object.Reference.IsVisible = true;
}
}
if (!object.IsSelected) {
toRedraw = this.UnSelect();
this.selected.push(object);
if (gdCanvasCustomTypes.CustomObject.Select(object)) {
var layer = this.canvas.map.get(object.Type);
if (layer !== undefined) {
var type = Types[object.Type].toString();
if (toRedraw.indexOf(type) === -1)
toRedraw.push(type);
var child = this.canvas.mapChildren.get(object.Type);
if (child !== undefined) {
var type = Types[child].toString();
if (toRedraw.indexOf(type) === -1)
toRedraw.push(type);
}
}
var layer = this.canvas.map.get(object.ParentType);
if (layer !== undefined) {
var type = Types[object.ParentType].toString();
if (toRedraw.indexOf(type) === -1)
toRedraw.push(type);
}
}
if (object.type === Types.reference) {
object.IsVisible = true;
object.Select();
}
}
}
if (this.focused !== null && this.focused !== object) {
this.focused.IsFocused = false;
this.focused.activePoint = -1;
this.focused.activeLine = -1;
if (!object.IsSelected) {
this.focused.IsSelected = false;
}
}
this.focused = object;
this.focused.IsFocused = true;
this.focused.IsSelected = true;
this.focused.ClickOffsetX = point.x - this.focused.X;
this.focused.ClickOffsetY = point.y - this.focused.Y;
}
else {
if (object.type === Types.polygon) {
if (object.Text.IsFocused) {
this.selected.push(object);
}
else {
if (!object.IsSelected) {
this.UnSelect();
}
if (object.activeLine !== -1) {
this.selected.push(object);
}
}
}
else {
if (!object.IsSelected) {
this.selected.push(object);
if (gdCanvasCustomTypes.CustomObject.Select(object)) {
var layer = this.canvas.map.get(object.Type);
if (layer !== undefined) {
var type = Types[object.Type].toString();
if (toRedraw.indexOf(type) === -1)
toRedraw.push(type);
}
var layer = this.canvas.map.get(object.ParentType);
if (layer !== undefined) {
var type = Types[object.ParentType].toString();
if (toRedraw.indexOf(type) === -1)
toRedraw.push(type);
}
}
if (object.type === Types.reference) {
object.IsVisible = true;
}
if (object.type === Types.shape) {
if (object.IsRef)
object.Reference.IsVisible = true;
}
if (this.focused !== null) {
this.focused.IsFocused = false;
this.focused.activePoint = -1;
this.focused.activeLine = -1;
}
this.focused = object;
this.focused.IsFocused = true;
this.focused.IsSelected = true;
this.focused.ClickOffsetX = point.x - this.focused.X;
this.focused.ClickOffsetY = point.y - this.focused.Y;
}
else {
var i = this.selected.indexOf(object);
if (i > -1) {
this.selected.splice(i, 1);
}
object.IsSelected = false;
if (object.IsFocused) {
this.focused.IsFocused = false;
this.focused.activePoint = -1;
this.focused.activeLine = -1;
this.focused = null;
if (this.selected.length > 0) {
this.focused = this.selected[0];
this.focused.IsFocused = true;
}
}
}
}
}
var newSelected = Types[object.type];
if (toRedraw.indexOf(newSelected) === -1)
toRedraw.push(Types[object.type]);
if (toRedraw.indexOf('selected') === -1)
toRedraw.push('selected');
if (object.isRef)
if (toRedraw.indexOf('reference') === -1)
toRedraw.push('reference');
if (object.type === Types.text && object.ParentType === Types.polygon)
if (toRedraw.indexOf('polygon') === -1)
toRedraw.push('polygon');
this.canvas.DRAW(toRedraw);
return true;
};
Selector.prototype.UnSelect = function () {
if (this.selected.length === 0)
return [];
var wasSelected = new Array();
wasSelected.push('selected');
for (var i = 0; i < this.selected.length; ++i) {
this.selected[i].IsSelected = false;
if (gdCanvasCustomTypes.CustomObject.UnSelect(this.selected[i])) {
var child = this.canvas.mapChildren.get(this.selected[i].type);
if (child !== undefined) {
var type = Types[child].toString();
if (wasSelected.indexOf(type) === -1)
wasSelected.push(type);
type = Types[this.selected[i].type].toString();
if (wasSelected.indexOf(type) === -1)
wasSelected.push(type);
}
}
switch (this.selected[i].type) {
case Types.block:
{
if (wasSelected.indexOf('block') === -1)
wasSelected.push('block');
}
break;
case Types.dimension:
{
if (wasSelected.indexOf('dimension') === -1)
wasSelected.push('dimension');
}
break;
case Types.segment:
{
if (wasSelected.indexOf('segment') === -1)
wasSelected.push('segment');
}
break;
case Types.arc:
{
if (wasSelected.indexOf('arc') === -1)
wasSelected.push('arc');
}
break;
case Types.polygon:
{
if (wasSelected.indexOf('polygon') === -1)
wasSelected.push('polygon');
}
break;
case Types.callout:
{
if (wasSelected.indexOf('callout') === -1)
wasSelected.push('callout');
}
break;
case Types.polyline:
{
if (wasSelected.indexOf('polyline') === -1)
wasSelected.push('polyline');
this.selected[i].activePoint = -1;
this.selected[i].activeLine = -1;
this.selected[i].activeLineKeeper = -1;
}
break;
case Types.reference:
{
this.selected[i].IsVisible = false;
if (wasSelected.indexOf('reference') === -1)
wasSelected.push('reference');
for (var j = 0; j < this.selected[i].Children.length; ++j) {
var toRedraw = Types[this.selected[i].Children[j].type];
if (wasSelected.indexOf(toRedraw) === -1)
wasSelected.push(toRedraw);
}
}
break;
case Types.shape:
{
if (gdCanvasCustomTypes.CustomObject.UnSelect(this.selected[i])) {
var layer = this.canvas.map.get(this.selected[i].ParentType);
if (layer !== null) {
var type = Types[this.selected[i].ParentType].toString();
if (wasSelected.indexOf(type) === -1)
wasSelected.push(type);
}
}
if (this.selected[i].IsRef) {
this.selected[i].Reference.IsVisible = false;
if (this.selected[i].Reference.IsRef) {
this.selected[i].Reference.Reference.IsVisible = false;
}
if (wasSelected.indexOf('reference') === -1)
wasSelected.push('reference');
}
if (wasSelected.indexOf('shape') === -1)
wasSelected.push('shape');
}
break;
case Types.text:
{
if (this.selected[i].ParentType === Types.polygon) {
if (wasSelected.indexOf('polygon') === -1)
wasSelected.push('polygon');
}
else {
if (wasSelected.indexOf('text') === -1)
wasSelected.push('text');
}
}
break;
}
}
this.ClearSelection();
return wasSelected;
};
Selector.prototype.IsContains = function (point) {
return false;
};
Selector.prototype.Draw = function (c) {
if (c === null || c === undefined)
return;
this.Refresh();
var borderThickness = 0.25;
c.clearRect(-0.5, -0.5, this.canvas.width + 1, this.canvas.height + 1);
if (this.canvas.action === Actions.select || this.canvas.action === Actions.selectShapes) {
c.save();
c.fillStyle = 'rgba(128, 159, 255, 0.15)';
c.strokeStyle = 'rgba( 0, 45, 179, 1.00)';
c.lineWidth = borderThickness;
c.beginPath();
c.rect(this.rect.x + (0.5 / this.canvas.scale), this.rect.y + (0.5 / this.canvas.scale), this.rect.w, this.rect.h);
c.closePath();
c.fill();
c.stroke();
c.restore();
}
if (this.canvas.action === Actions.selectShapesInOrder) {
c.save();
c.strokeStyle = 'rgba( 0, 45, 179, 1.00)';
c.lineWidth = borderThickness;
c.beginPath();
c.moveTo(this.startX, this.startY);
c.lineTo(this.endX, this.endY);
c.closePath();
c.stroke();
c.restore();
}
gdCanvasCustomTypes.CustomObject.DoCustomAction(c, this.canvas.action, this.startX, this.startY, this.endX, this.endY, this.canvas.scale, borderThickness);
};
Selector.prototype.DrawRegularGondola = function (c) {
var LocationW = 40;
var LocationH = 20;
var Start = 0;
var End = 0;
try {
var start = new gdCommon.Point(this.StartX / this.canvas.scale, this.StartY / this.canvas.scale);
var end = new gdCommon.Point(this.EndX / this.canvas.scale, this.EndY / this.canvas.scale);
var vector = new gdCommon.Vector(start, end);
var angle = vector.Angle();
var len = vector.Length();
var vectorStartCap = new gdCommon.Vector(start, end);
vectorStartCap.Normalize();
vectorStartCap.Scale(-LocationH);
var vectorEndCap = new gdCommon.Vector(start, end);
vectorEndCap.Normalize();
vectorEndCap.Scale(LocationH);
var vector1 = new gdCommon.Vector(start, end);
vector1.Rotate90();
vector1.Normalize();
vector1.Scale(LocationH);
var vector2 = new gdCommon.Vector(start, end);
vector2.Rotate90();
vector2.Rotate90();
vector2.Rotate90();
vector2.Normalize();
vector2.Scale(LocationH);
var gondola = new gdCommon.Line(this.startX, this.startY, this.endX, this.endY);
var line1 = new gdCommon.Line(this.startX + vector2.x, this.startY + vector2.y, this.startX + vector1.x, this.startY + vector1.y);
var line2 = new gdCommon.Line(this.startX + vector1.x, this.startY + vector1.y, this.endX + vector1.x, this.endY + vector1.y);
var line3 = new gdCommon.Line(this.endX + vector1.x, this.endY + vector1.y, this.endX + vector2.x, this.endY + vector2.y);
var line4 = new gdCommon.Line(this.endX + vector2.x, this.endY + vector2.y, this.startX + vector2.x, this.startY + vector2.y);
var line5 = new gdCommon.Line(this.startX + vector1.x, this.startY + vector1.y, this.startX + vectorStartCap.x + vector1.x, this.startY + vectorStartCap.y + vector1.y);
var line6 = new gdCommon.Line(this.startX + vectorStartCap.x + vector1.x, this.startY + vectorStartCap.y + vector1.y, this.startX + vectorStartCap.x + vector2.x, this.startY + vectorStartCap.y + vector2.y);
var line7 = new gdCommon.Line(this.startX + vectorStartCap.x + vector2.x, this.startY + vectorStartCap.y + vector2.y, this.startX + vector2.x, this.startY + vector2.y);
var line8 = new gdCommon.Line(this.endX + vector1.x, this.endY + vector1.y, this.endX + vectorEndCap.x + vector1.x, this.endY + vectorEndCap.y + vector1.y);
var line9 = new gdCommon.Line(this.endX + vectorEndCap.x + vector1.x, this.endY + vectorEndCap.y + vector1.y, this.endX + vectorEndCap.x + vector2.x, this.endY + vectorEndCap.y + vector2.y);
var line10 = new gdCommon.Line(this.endX + vectorEndCap.x + vector2.x, this.endY + vectorEndCap.y + vector2.y, this.endX + vector2.x, this.endY + vector2.y);
c.beginPath();
c.moveTo(gondola.x1, gondola.y1);
c.lineTo(gondola.x2, gondola.y2);
c.moveTo(line1.x1, line1.y1);
c.lineTo(line1.x2, line1.y2);
c.lineTo(line2.x2, line2.y2);
c.lineTo(line3.x2, line3.y2);
c.lineTo(line4.x2, line4.y2);
c.moveTo(line5.x1, line5.y1);
c.lineTo(line5.x2, line5.y2);
c.lineTo(line6.x2, line6.y2);
c.lineTo(line7.x2, line7.y2);
c.moveTo(line8.x1, line8.y1);
c.lineTo(line8.x2, line8.y2);
c.lineTo(line9.x2, line9.y2);
c.lineTo(line10.x2, line10.y2);
c.closePath();
c.stroke();
var vector3 = new gdCommon.Vector(start, end);
var tempID = 1;