gojs
Version:
Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams
1,134 lines (1,126 loc) • 246 kB
JavaScript
/*! Copyright (C) 1998-2020 by Northwoods Software Corporation. All Rights Reserved. */
window["gfp"] =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
(function() { module.exports = window["go"]; }());
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
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);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var go = __webpack_require__(0);
var WallBuildingTool = (function (_super) {
__extends(WallBuildingTool, _super);
function WallBuildingTool() {
var _this = _super.call(this) || this;
_this._buildingWall = null;
_this._isBuildingDivider = false;
_this.name = 'WallBuilding';
_this._startPoint = null;
_this._endPoint = null;
_this._wallReshapingTool = null;
_this._isBuildingDivider = false;
return _this;
}
Object.defineProperty(WallBuildingTool.prototype, "startPoint", {
get: function () { return this._startPoint; },
set: function (value) { this._startPoint = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallBuildingTool.prototype, "endPoint", {
get: function () { return this._endPoint; },
set: function (value) { this._endPoint = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallBuildingTool.prototype, "wallReshapingTool", {
get: function () { return this._wallReshapingTool; },
set: function (value) { this._wallReshapingTool = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallBuildingTool.prototype, "buildingWall", {
get: function () { return this._buildingWall; },
set: function (value) { this._buildingWall = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallBuildingTool.prototype, "isBuildingDivider", {
get: function () { return this._isBuildingDivider; },
set: function (value) { this._isBuildingDivider = value; },
enumerable: true,
configurable: true
});
WallBuildingTool.prototype.doActivate = function () {
this.endPoint = null;
this.startTransaction(this.name);
this.diagram.isMouseCaptured = true;
var tool = this;
var fp = tool.diagram;
var clickPt = tool.diagram.lastInput.documentPoint;
var isSnapped = false;
var walls = fp.findNodesByExample({ category: 'WallGroup' });
walls.iterator.each(function (w) {
if (fp.isPointInWall(w, clickPt)) {
if (tool.buildingWall === null) {
var snapPt = clickPt.projectOntoLineSegmentPoint(w.data.startpoint, w.data.endpoint);
clickPt = snapPt;
isSnapped = true;
}
}
});
walls.iterator.each(function (w) {
var sp = w.data.startpoint;
var ep = w.data.endpoint;
var distSp = Math.sqrt(sp.distanceSquaredPoint(clickPt));
if (distSp < 15) {
clickPt = sp;
isSnapped = true;
}
var distEp = Math.sqrt(ep.distanceSquaredPoint(clickPt));
if (distEp < 15) {
clickPt = ep;
isSnapped = true;
}
});
if (true) {
var gs = fp.model.modelData.gridSize;
if (!(tool.diagram.toolManager.draggingTool.isGridSnapEnabled) || isSnapped)
gs = .0001;
var newx = gs * Math.round(clickPt.x / gs);
var newy = gs * Math.round(clickPt.y / gs);
clickPt = new go.Point(newx, newy);
}
this.startPoint = clickPt;
this.wallReshapingTool = fp.toolManager.mouseDownTools.elt(3);
this.isActive = true;
};
WallBuildingTool.prototype.doMouseDown = function () {
var diagram = this.diagram;
var tool = this;
tool.diagram.currentCursor = 'crosshair';
var data = {
key: 'wall', category: 'WallGroup', caption: tool.isBuildingDivider ? 'Divider' : 'Wall', type: tool.isBuildingDivider ? 'Divider' : 'Wall',
startpoint: tool.startPoint, endpoint: tool.startPoint, smpt1: tool.startPoint, smpt2: tool.startPoint, empt1: tool.startPoint, empt2: tool.startPoint,
thickness: tool._isBuildingDivider ? .005 : parseFloat(diagram.model.modelData.wallThickness), color: 'lightgray', isGroup: true, notes: '',
isDivider: tool.isBuildingDivider
};
this.diagram.model.addNodeData(data);
var wall = diagram.findPartForKey(data.key);
this.buildingWall = wall;
var fp = diagram;
fp.updateWall(wall);
var part = diagram.findPartForData(data);
if (part === null)
return;
tool.transactionResult = tool.name;
diagram.raiseDiagramEvent('PartCreated', part);
if (tool.wallReshapingTool === null)
return;
tool.wallReshapingTool.isEnabled = true;
diagram.select(part);
tool.wallReshapingTool.isBuilding = true;
tool.wallReshapingTool.adornedShape = part.findObject('SHAPE');
tool.wallReshapingTool.doActivate();
};
WallBuildingTool.prototype.doKeyDown = function () {
var fp = this.diagram;
var e = fp.lastInput;
if (e.key === 'Esc') {
var wall = fp.selection.first();
fp.remove(wall);
fp.pointNodes.iterator.each(function (node) { fp.remove(node); });
fp.dimensionLinks.iterator.each(function (link) { fp.remove(link); });
fp.pointNodes.clear();
fp.dimensionLinks.clear();
this.doDeactivate();
}
go.Tool.prototype.doKeyDown.call(this);
};
WallBuildingTool.prototype.doMouseMove = function () {
if (this.wallReshapingTool === null)
return;
this.diagram.currentCursor = 'crosshair';
this.wallReshapingTool.doMouseMove();
};
WallBuildingTool.prototype.doDeactivate = function () {
var diagram = this.diagram;
this.buildingWall = null;
this.diagram.currentCursor = '';
this.diagram.isMouseCaptured = false;
if (this.wallReshapingTool !== null) {
this.wallReshapingTool.isEnabled = false;
this.wallReshapingTool.adornedShape = null;
this.wallReshapingTool.doMouseUp();
this.wallReshapingTool.doDeactivate();
this.wallReshapingTool.isBuilding = false;
}
var fp = diagram;
fp.updateWallDimensions();
this.stopTransaction();
this.isActive = false;
};
return WallBuildingTool;
}(go.Tool));
exports.WallBuildingTool = WallBuildingTool;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
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);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var go = __webpack_require__(0);
var WallReshapingTool = (function (_super) {
__extends(WallReshapingTool, _super);
function WallReshapingTool() {
var _this = _super.call(this) || this;
var h = new go.Shape();
h.figure = 'Diamond';
h.desiredSize = new go.Size(12, 12);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
h.cursor = 'move';
_this._handleArchetype = h;
_this._handle = null;
_this._adornedShape = null;
_this._reshapeObjectName = 'SHAPE';
_this._angle = 0;
_this._length = 0;
_this._isBuilding = false;
_this._isIntersecting = false;
_this._joinedWalls = new go.Set();
_this._returnPoint = null;
_this._returnData = null;
_this._joinedWalls = new go.Set();
_this._wallIntersecting = null;
return _this;
}
Object.defineProperty(WallReshapingTool.prototype, "handleArchetype", {
get: function () { return this._handleArchetype; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "handle", {
get: function () { return this._handle; },
set: function (value) { this._handle = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "adornedShape", {
get: function () { return this._adornedShape; },
set: function (value) { this._adornedShape = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "angle", {
get: function () { return this._angle; },
set: function (value) { this._angle = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "length", {
get: function () { return this._length; },
set: function (value) { this._length = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "reshapeObjectName", {
get: function () { return this._reshapeObjectName; },
set: function (value) { this._reshapeObjectName = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "isBuilding", {
get: function () { return this._isBuilding; },
set: function (value) { this._isBuilding = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "returnData", {
get: function () { return this._returnData; },
set: function (value) { this._returnData = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "returnPoint", {
get: function () { return this._returnPoint; },
set: function (value) { this._returnPoint = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "isIntersecting", {
get: function () { return this._isIntersecting; },
set: function (value) { this._isIntersecting = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "wallIntersecting", {
get: function () { return this._wallIntersecting; },
set: function (value) { this._wallIntersecting = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(WallReshapingTool.prototype, "joinedWalls", {
get: function () { return this._joinedWalls; },
set: function (value) { this._joinedWalls = value; },
enumerable: true,
configurable: true
});
WallReshapingTool.prototype.updateAdornments = function (part) {
if (part === null || part instanceof go.Link)
return;
if (part.isSelected && !this.diagram.isReadOnly) {
var seleltgo = part.findObject(this.reshapeObjectName);
if (seleltgo !== null && seleltgo.part !== null && seleltgo.part.data.category === 'WallGroup') {
var selelt = seleltgo;
var adornment = part.findAdornment(this.name);
if (adornment === null) {
adornment = this.makeAdornment(selelt);
}
if (adornment !== null && selelt.part !== null && selelt.geometry != null) {
var geo = selelt.geometry;
var b_1 = geo.bounds;
var pb_1 = selelt.part.actualBounds;
var graphObj = adornment.findObject('BODY');
if (graphObj === null)
return;
graphObj.desiredSize = b_1.size;
adornment.elements.each(function (h) {
if (h.name === undefined)
return;
var x = 0;
var y = 0;
switch (h.name) {
case 'sPt': {
x = part.data.startpoint.x - pb_1.x;
y = part.data.startpoint.y - pb_1.y;
break;
}
case 'ePt': {
x = part.data.endpoint.x - pb_1.x;
y = part.data.endpoint.y - pb_1.y;
break;
}
}
var xCheck = Math.min((x - b_1.x) / b_1.width, 1);
var yCheck = Math.min((y - b_1.y) / b_1.height, 1);
if (xCheck < 0)
xCheck = 0;
if (yCheck < 0)
yCheck = 0;
if (xCheck > 1)
xCheck = 1;
if (yCheck > 1)
yCheck = 1;
if (isNaN(xCheck))
xCheck = 0;
if (isNaN(yCheck))
yCheck = 0;
h.alignment = new go.Spot(Math.max(0, xCheck), Math.max(0, yCheck));
});
part.addAdornment(this.name, adornment);
adornment.location = selelt.getDocumentPoint(go.Spot.Center);
return;
}
}
}
part.removeAdornment(this.name);
};
WallReshapingTool.prototype.canStart = function () {
if (!this.isEnabled)
return false;
var diagram = this.diagram;
if (diagram === null || diagram.isReadOnly)
return false;
if (!diagram.allowReshape)
return false;
if (!diagram.lastInput.left)
return false;
var h = this.findToolHandleAt(diagram.firstInput.documentPoint, this.name);
return (h !== null || this.isBuilding);
};
WallReshapingTool.prototype.doActivate = function () {
var diagram = this.diagram;
if (diagram === null)
return;
if (this.isBuilding) {
if (this.adornedShape !== null && this.adornedShape.part !== null) {
var wall = this.adornedShape.part;
this.handle = this.findToolHandleAt(wall.data.endpoint, this.name);
this.returnPoint = wall.data.startpoint;
}
}
else {
this.handle = this.findToolHandleAt(diagram.firstInput.documentPoint, this.name);
if (this.handle === null)
return;
var adorn = this.handle.part;
var shape = adorn.adornedObject;
var wall = shape.part;
if (!shape)
return;
this.adornedShape = shape;
this.returnPoint = this.handle.name === 'sPt' ? wall.data.startpoint : wall.data.endpoint;
var wallParts = wall.memberParts;
if (wallParts.count !== 0) {
var locationsMap_1 = new go.Map();
wallParts.iterator.each(function (wallPart) {
locationsMap_1.add(wallPart.data.key, wallPart.location);
});
this.returnData = locationsMap_1;
}
}
this.startTransaction(this.name);
this.isActive = true;
};
WallReshapingTool.prototype.doMouseMove = function () {
var fp = this.diagram;
var tool = this;
if (tool.handle === null)
return;
var adorn = tool.handle.part;
var wall = adorn.adornedPart;
var mousePt = fp.lastInput.documentPoint;
if (tool.isActive && fp !== null) {
if (fp.lastInput.shift) {
var type = tool.handle.name;
var stationaryPt = (type === 'sPt') ? wall.data.endpoint : wall.data.startpoint;
var ang = stationaryPt.directionPoint(mousePt);
var length_1 = Math.sqrt(stationaryPt.distanceSquaredPoint(mousePt));
ang = Math.round(ang / 45) * 45;
var newPoint = new go.Point(stationaryPt.x + length_1, stationaryPt.y);
var dx = stationaryPt.x;
var dy = stationaryPt.y;
newPoint = newPoint.offset(-dx, -dy);
newPoint = newPoint.rotate(ang);
newPoint = newPoint.offset(dx, dy);
mousePt = newPoint;
}
var walls = fp.findNodesByExample({ category: 'WallGroup' });
walls.iterator.each(function (w) {
if (w.data.key !== wall.data.key) {
var spt = w.data.startpoint;
var ept = w.data.endpoint;
if (fp.isPointInWall(w, mousePt)) {
mousePt = mousePt.projectOntoLineSegmentPoint(w.data.startpoint, w.data.endpoint);
tool.isIntersecting = true;
}
if (Math.sqrt(spt.distanceSquaredPoint(mousePt)) < 10) {
mousePt = spt;
}
else if (Math.sqrt(ept.distanceSquaredPoint(mousePt)) < 10) {
mousePt = ept;
}
}
});
var iw = tool.getClosestIntersectingWall(mousePt);
if (iw === null || tool.wallIntersecting !== null) {
if (tool.wallIntersecting !== null && tool.wallIntersecting !== undefined && tool.wallIntersecting.data !== null) {
tool.performMiteringOnWall(tool.wallIntersecting);
}
}
if (iw != null) {
tool.isIntersecting = true;
tool.wallIntersecting = iw;
mousePt = mousePt.projectOntoLineSegmentPoint(iw.data.startpoint, iw.data.endpoint);
var distToSpt = Math.sqrt(mousePt.distanceSquaredPoint(iw.data.startpoint));
var distToEpt = Math.sqrt(mousePt.distanceSquaredPoint(iw.data.endpoint));
if (distToSpt < 25) {
mousePt = iw.data.startpoint;
}
else if (distToEpt < 10) {
mousePt = iw.data.endpoint;
}
}
else {
tool.isIntersecting = false;
if (tool.wallIntersecting !== null && tool.wallIntersecting !== undefined &&
tool.wallIntersecting.data !== null && fp.getWallsIntersection(wall, tool.wallIntersecting) === null) {
tool.wallIntersecting = null;
}
}
tool.calcAngleAndLengthFromHandle(mousePt);
tool.reshape(mousePt);
}
tool.performMiteringOnWall(wall);
fp.updateWallDimensions();
fp.updateWallAngles();
};
WallReshapingTool.prototype.getClosestIntersectingWall = function (proposedPt) {
var tool = this;
if (tool.handle === null)
return null;
var adorn = tool.handle.part;
var wall = adorn.adornedPart;
var type = tool.handle.name;
var stationaryPt = (type === 'sPt') ? wall.data.endpoint : wall.data.startpoint;
var dummyWallData = {
key: 'wall', category: 'WallGroup', caption: 'Wall', type: 'Wall', startpoint: stationaryPt,
smpt1: stationaryPt, smpt2: stationaryPt, endpoint: proposedPt, empt1: proposedPt, empt2: proposedPt,
thickness: parseFloat(tool.diagram.model.modelData.wallThickness), isGroup: true, notes: ''
};
tool.diagram.model.addNodeData(dummyWallData);
var dummyWall = tool.diagram.findPartForKey(dummyWallData.key);
var fp = tool.diagram;
var walls = tool.diagram.findNodesByExample({ category: 'WallGroup' });
var closestWall = null;
var closestDistance = Number.MAX_VALUE;
walls.iterator.each(function (w) {
if (w.data.key !== wall.data.key && w.data.key !== dummyWall.data.key) {
var intersectPoint = fp.getWallsIntersection(dummyWall, w);
var isStationaryPtOnW = false;
var ab = parseFloat(Math.sqrt(w.data.startpoint.distanceSquaredPoint(stationaryPt)).toFixed(2));
var bc = parseFloat(Math.sqrt(stationaryPt.distanceSquaredPoint(w.data.endpoint)).toFixed(2));
var ac = parseFloat(Math.sqrt(w.data.startpoint.distanceSquaredPoint(w.data.endpoint)).toFixed(2));
if (Math.abs((ab + bc) - ac) <= .1) {
isStationaryPtOnW = true;
}
if (intersectPoint !== null && !isStationaryPtOnW) {
var dist = Math.sqrt(stationaryPt.distanceSquaredPoint(intersectPoint));
if (dist < closestDistance) {
closestDistance = dist;
closestWall = w;
}
}
}
});
fp.remove(dummyWall);
return closestWall;
};
WallReshapingTool.prototype.pointsApproximatelyEqual = function (p1, p2) {
var x1 = p1.x;
var x2 = p2.x;
var y1 = p1.y;
var y2 = p2.y;
var diff1 = Math.abs(x2 - x1);
var diff2 = Math.abs(y2 - y1);
if (diff2 < .05 && diff1 < .05) {
return true;
}
return false;
};
WallReshapingTool.prototype.performMitering = function (wa, wb) {
var tool = this;
var diagram = this.diagram;
var as = wa.data.startpoint;
var ae = wa.data.endpoint;
var bs = wb.data.startpoint;
var be = wb.data.endpoint;
var wat = wa.data.thickness;
var wbt = wb.data.thickness;
var wal = Math.sqrt(as.distanceSquaredPoint(ae));
var wbl = Math.sqrt(bs.distanceSquaredPoint(be));
var B = diagram.getWallsIntersection(wa, wb);
if (B === null) {
return;
}
var A = (tool.pointsApproximatelyEqual(as, B)) ? ae : as;
var C = (tool.pointsApproximatelyEqual(bs, B)) ? be : bs;
var ow = null;
var iw = null;
if (!tool.pointsApproximatelyEqual(as, B) && !tool.pointsApproximatelyEqual(ae, B)) {
ow = wa;
iw = wb;
}
else if (!tool.pointsApproximatelyEqual(bs, B) && !tool.pointsApproximatelyEqual(be, B)) {
ow = wb;
iw = wa;
}
if (ow !== null && iw !== null && wa.data.key === iw.data.key) {
if (tool.isClockwise(A, B, ow.data.startpoint)) {
C = ow.data.startpoint;
}
else {
C = ow.data.endpoint;
}
}
if (ow !== null && iw !== null && wb.data.key === iw.data.key) {
if (tool.isClockwise(B, C, ow.data.startpoint)) {
A = ow.data.startpoint;
}
else {
A = ow.data.endpoint;
}
}
var a1 = B.directionPoint(A);
var a2 = B.directionPoint(C);
var ang = Math.abs(a1 - a2 + 360) % 360;
if (Math.abs(ang - 180) < .1) {
return;
}
ang = ang * (Math.PI / 180);
var u = Math.abs(wbt / (2 * (Math.sin(ang))));
var v = Math.abs(wat / (2 * (Math.sin(ang))));
var ab = Math.sqrt(A.distanceSquaredPoint(B));
var bc = Math.sqrt(B.distanceSquaredPoint(C));
var ux = ((A.x - B.x) / ab) * u;
var uy = ((A.y - B.y) / ab) * u;
var vx = ((C.x - B.x) / bc) * v;
var vy = ((C.y - B.y) / bc) * v;
var D = new go.Point(B.x + ux + vx, B.y + uy + vy);
var E = new go.Point(B.x - ux - vx, B.y - uy - vy);
var minLength = Math.min(wal, wbl);
if (Math.sqrt(D.distanceSquaredPoint(B)) > minLength) {
return;
}
var mpt = tool.isClockwise(B, A, D) ? E : D;
if (isNaN(mpt.x) || isNaN(mpt.y)) {
return;
}
if (tool.pointsApproximatelyEqual(as, B) || tool.pointsApproximatelyEqual(ae, B)) {
var prop = null;
if (tool.pointsApproximatelyEqual(A, as)) {
if (tool.isClockwise(A, B, mpt)) {
prop = 'empt1';
}
else {
prop = 'empt2';
}
}
else if (tool.pointsApproximatelyEqual(A, ae)) {
if (tool.isClockwise(A, B, mpt)) {
prop = 'smpt2';
}
else {
prop = 'smpt1';
}
}
if (prop !== null) {
diagram.model.setDataProperty(wa.data, prop, mpt);
diagram.updateWall(wa);
}
}
if (tool.pointsApproximatelyEqual(bs, B) || tool.pointsApproximatelyEqual(be, B)) {
var prop = null;
if (tool.pointsApproximatelyEqual(C, bs)) {
if (tool.isClockwise(C, B, mpt)) {
prop = 'empt1';
}
else {
prop = 'empt2';
}
}
else if (tool.pointsApproximatelyEqual(C, be)) {
if (tool.isClockwise(C, B, mpt)) {
prop = 'smpt2';
}
else {
prop = 'smpt1';
}
}
if (prop !== null) {
diagram.model.setDataProperty(wb.data, prop, mpt);
diagram.updateWall(wb);
}
}
};
WallReshapingTool.prototype.getAllWallIntersectionPoints = function () {
var tool = this;
var diagram = tool.diagram;
var walls = diagram.findNodesByExample({ category: 'WallGroup' });
var intersectionPoints = new go.Set();
walls.iterator.each(function (w) {
var otherWalls = diagram.findNodesByExample({ category: 'WallGroup' });
otherWalls.iterator.each(function (ow) {
if (ow.data.key === w.data.key)
return;
var ip = diagram.getWallsIntersection(w, ow);
var doAdd = true;
if (ip !== null) {
intersectionPoints.iterator.each(function (ips) {
var ip2 = go.Point.parse(ips);
if (tool.pointsApproximatelyEqual(ip2, ip)) {
doAdd = false;
}
});
if (doAdd) {
intersectionPoints.add(go.Point.stringify(ip));
}
}
});
});
return intersectionPoints;
};
WallReshapingTool.prototype.getAllWallsAtIntersection = function (intersectionPoint, includeDividers) {
if (includeDividers === undefined || includeDividers === null) {
includeDividers = true;
}
var tool = this;
var diagram = tool.diagram;
var wallsInvolved = new go.List();
if (intersectionPoint === null) {
return wallsInvolved;
}
diagram.findObjectsNear(intersectionPoint, 1, function (x) {
if (x.part !== null) {
return x.part;
}
return null;
}, function (p) {
if (!(p instanceof go.Group && p.category === 'WallGroup' && (includeDividers || !p.data.isDivider) && !wallsInvolved.contains(p)))
return false;
var s = p.data.startpoint;
var e = p.data.endpoint;
return tool.isPointOnSegment(s, e, intersectionPoint);
}, true, wallsInvolved);
return wallsInvolved;
};
WallReshapingTool.prototype.doWallsShareAnEndpoint = function (wa, wb) {
var tool = this;
var as = wa.data.startpoint;
var ae = wa.data.endpoint;
var bs = wb.data.startpoint;
var be = wb.data.endpoint;
if (tool.pointsApproximatelyEqual(as, bs) || tool.pointsApproximatelyEqual(as, be)
|| tool.pointsApproximatelyEqual(ae, bs) || tool.pointsApproximatelyEqual(ae, be)) {
return true;
}
return false;
};
WallReshapingTool.prototype.maybeSplitWall = function () {
var tool = this;
if (tool.handle === null)
return;
var adorn = tool.handle.part;
var reshapingWall = adorn.adornedPart;
var movingProp = tool.handle.name;
var movingPt = movingProp === 'sPt' ? reshapingWall.data.startpoint : reshapingWall.data.endpoint;
var jw = tool.joinedWalls;
var wallsAtEndpoint = tool.getAllWallsAtIntersection(movingPt);
wallsAtEndpoint.remove(reshapingWall);
jw.iterator.each(function (ww) {
wallsAtEndpoint.remove(ww);
});
if (wallsAtEndpoint.count === 1) {
var wallToSplit = wallsAtEndpoint.first();
if (wallToSplit !== null) {
if (!tool.doWallsShareAnEndpoint(reshapingWall, wallToSplit)) {
tool.maybePerformWallSplit(wallToSplit, movingPt);
}
}
}
if (tool.isBuilding) {
var stationaryPt = movingPt === reshapingWall.data.startpoint ? reshapingWall.data.endpoint : reshapingWall.data.startpoint;
var wallsAtStationaryPt = tool.getAllWallsAtIntersection(stationaryPt);
wallsAtStationaryPt.remove(reshapingWall);
jw.iterator.each(function (ww) {
wallsAtEndpoint.remove(ww);
});
if (wallsAtStationaryPt.count === 1) {
var wallToSplit = wallsAtStationaryPt.first();
if (wallToSplit !== null) {
if (!tool.doWallsShareAnEndpoint(reshapingWall, wallToSplit)) {
tool.maybePerformWallSplit(wallToSplit, stationaryPt);
}
}
}
}
if (jw !== null) {
jw.iterator.each(function (ww) {
tool.splitNewWall(ww);
});
}
};
WallReshapingTool.prototype.splitNewWall = function (w) {
var tool = this;
var fp = this.diagram;
var walls = fp.findNodesByExample({ category: 'WallGroup' });
var ips = new go.Set();
walls.iterator.each(function (ww) {
var ip = fp.getWallsIntersection(w, ww);
if (ip !== null) {
ips.add(ip);
}
});
ips.iterator.each(function (ip) {
var wi = tool.getAllWallsAtIntersection(ip);
wi.iterator.each(function (ww) {
var s = ww.data.startpoint;
var e = ww.data.endpoint;
if (!tool.pointsApproximatelyEqual(s, ip) && !tool.pointsApproximatelyEqual(e, ip)) {
tool.maybePerformWallSplit(ww, ip);
}
});
});
};
WallReshapingTool.prototype.maybePerformWallSplit = function (w, ip) {
var tool = this;
var fp = tool.diagram;
var s = w.data.startpoint;
var e = w.data.endpoint;
var type = w.data.isDivider ? 'Divider' : 'Wall';
var data1 = {
key: 'wall', category: 'WallGroup', caption: type, type: type, color: w.data.color,
startpoint: s, endpoint: ip, smpt1: s, smpt2: s, empt1: ip, empt2: ip,
thickness: w.data.thickness, isGroup: true, notes: '',
isDivider: w.data.isDivider
};
var data2 = {
key: 'wall', category: 'WallGroup', caption: type, type: type, color: w.data.color,
startpoint: ip, endpoint: e, smpt1: ip, smpt2: ip, empt1: e, empt2: e,
thickness: w.data.thickness, isGroup: true, notes: '',
isDivider: w.data.isDivider
};
var l1 = Math.sqrt(data1.startpoint.distanceSquaredPoint(data1.endpoint));
var l2 = Math.sqrt(data2.startpoint.distanceSquaredPoint(data2.endpoint));
var walls = fp.findNodesByExample({ category: 'WallGroup' });
var alreadyExists = false;
walls.iterator.each(function (wc) {
var ws = wc.data.startpoint;
var we = wc.data.endpoint;
if ((tool.pointsApproximatelyEqual(s, ws) && tool.pointsApproximatelyEqual(ip, we)) ||
(tool.pointsApproximatelyEqual(s, we) && tool.pointsApproximatelyEqual(ip, ws))) {
alreadyExists = true;
}
if ((tool.pointsApproximatelyEqual(ip, ws) && tool.pointsApproximatelyEqual(e, we)) ||
(tool.pointsApproximatelyEqual(ip, we) && tool.pointsApproximatelyEqual(e, ws))) {
alreadyExists = true;
}
});
if (l1 > 1 && l2 > 1 && !alreadyExists) {
fp.model.addNodeData(data1);
fp.model.addNodeData(data2);
var w1_1 = fp.findNodeForData(data1);
var w2_1 = fp.findNodeForData(data2);
tool.premiterWall(w1_1);
tool.premiterWall(w2_1);
tool.performMiteringAtPoint(ip, false);
if (tool.handle !== null) {
var rooms = fp.findNodesByExample({ category: 'RoomNode' });
var adorn = tool.handle.part;
var rw_1 = adorn.adornedPart;
rooms.iterator.each(function (r) {
var bw = r.data.boundaryWalls;
var _loop_1 = function (i) {
var entry = bw[i];
var wk = entry[0];
if (wk === w.data.key) {
var isConnectedToBounds_1 = false;
var nonIpEndpoint = (tool.pointsApproximatelyEqual(rw_1.data.startpoint, ip)) ? rw_1.data.endpoint : rw_1.data.startpoint;
var iw = tool.getAllWallsAtIntersection(nonIpEndpoint);
iw.iterator.each(function (ww) {
for (var j = 0; j < bw.length; j++) {
var ee = bw[j];
var wk2 = ee[0];
if (ww.data.key === wk2 && ww.data.key !== rw_1.data.key) {
isConnectedToBounds_1 = true;
}
}
});
if (isConnectedToBounds_1) {
var isW1ConnectedToBounds_1 = false;
var w1NonIpEndpoint_1 = (tool.pointsApproximatelyEqual(w1_1.data.startpoint, ip)) ? w1_1.data.endpoint : w1_1.data.startpoint;
var iw2 = tool.getAllWallsAtIntersection(w1NonIpEndpoint_1);
iw2.remove(w);
iw2.iterator.each(function (ww) {
var _loop_2 = function (j) {
var entry2 = bw[j];
var wk2 = entry2[0];
if (ww.data.key === wk2 && w1_1.data.key !== ww.data.key) {
var ww2_1 = fp.findNodeForKey(wk2);
var ww2OtherEndpoint = (tool.pointsApproximatelyEqual(ww2_1.data.startpoint, w1NonIpEndpoint_1)) ? ww2_1.data.endpoint : ww2_1.data.startpoint;
var iw3 = tool.getAllWallsAtIntersection(ww2OtherEndpoint);
iw3.iterator.each(function (ww3) {
for (var k = 0; k < bw.length; k++) {
var entry3 = bw[k];
var wk3 = entry3[0];
if (wk3 === ww3.data.key && wk3 !== ww2_1.data.key) {
isW1ConnectedToBounds_1 = true;
}
}
});
}
};
for (var j = 0; j < bw.length; j++) {
_loop_2(j);
}
});
var replacementWall = (isW1ConnectedToBounds_1) ? w1_1 : w2_1;
var replacementEntry = tool.getUpdatedEntry(entry, replacementWall);
fp.startTransaction();
var newBounds = bw.slice();
newBounds[i] = replacementEntry;
fp.model.setDataProperty(r.data, 'boundaryWalls', newBounds);
fp.commitTransaction();
}
else {
var wi = new go.List();
wi.add(rw_1);
wi.add(w1_1);
wi.add(w2_1);
wi = fp.sortWallsClockwiseWithSetStartWall(wi, rw_1);
var replacementEntry2 = tool.getUpdatedEntry(entry, wi.toArray()[1]);
var replacementEntry1 = tool.getUpdatedEntry(entry, wi.toArray()[2]);
fp.startTransaction();
var newBounds = bw.slice();
newBounds.splice(i, 1, replacementEntry1);
newBounds.splice(i + 1, 0, replacementEntry2);
fp.model.setDataProperty(r.data, 'boundaryWalls', newBounds);
fp.commitTransaction();
}
}
};
for (var i = 0; i < bw.length; i++) {
_loop_1(i);
}
});
}
var wallParts = fp.findNodesByExample({ group: w.data.key });
var wallsSet = new go.Set();
wallsSet.add(w1_1);
wallsSet.add(w2_1);
tool.maintainWallParts(wallParts, wallsSet);
fp.remove(w);
tool.premiterWall(w1_1);
tool.premiterWall(w2_1);
var w1op = tool.pointsApproximatelyEqual(w1_1.data.startpoint, ip) ? w1_1.data.endpoint : w1_1.data.startpoint;
var w2op = tool.pointsApproximatelyEqual(w2_1.data.startpoint, ip) ? w2_1.data.endpoint : w2_1.data.startpoint;
tool.performMiteringAtPoint(ip, false);
tool.performMiteringAtPoint(w1op, false);
tool.performMiteringAtPoint(w2op, false);
}
};
WallReshapingTool.prototype.splitAllWalls = function () {
var tool = this;
var intersectionPoints = tool.getAllWallIntersectionPoints();
intersectionPoints.iterator.each(function (ips) {
var ip = go.Point.parse(ips);
var wallsInvolved = tool.getAllWallsAtIntersection(ip);
wallsInvolved.iterator.each(function (w) {
var s = w.data.startpoint;
var e = w.data.endpoint;
if (!tool.pointsApproximatelyEqual(s, ip) && !tool.pointsApproximatelyEqual(e, ip)) {
tool.maybePerformWallSplit(w, ip);
}
});
});
};
WallReshapingTool.prototype.areWallsParallel = function (wa, wb) {
var tool = this;
var fp = this.diagram;
var as = wa.data.startpoint;
var ae = wa.data.endpoint;
var bs = wb.data.startpoint;
var be = wb.data.endpoint;
var isParallel = false;
var a1 = +as.directionPoint(ae);
var a2 = +bs.directionPoint(be);
if (Math.abs(a1 - a2) < 1 || (Math.abs(a1 - a2) > 179 && Math.abs(a1 - a2) < 181)) {
isParallel = true;
}
return isParallel;
};
WallReshapingTool.prototype.isWallColinear = function (wa, wb) {
var tool = this;
var fp = this.diagram;
if (wa.data.isDivider !== wb.data.isDivider) {
return false;
}
var as = wa.data.startpoint;
var ae = wa.data.endpoint;
var bs = wb.data.startpoint;
var be = wb.data.endpoint;
var isColinear = false;
if (tool.areWallsParallel(wa, wb)) {
var sharedEndpoint = null;
if (tool.pointsApproximatelyEqual(as, bs) || tool.pointsApproximatelyEqual(as, be)) {
sharedEndpoint = as;
}
else if (tool.pointsApproximatelyEqual(ae, bs) || tool.pointsApproximatelyEqual(ae, be)) {
sharedEndpoint = ae;
}
if (sharedEndpoint !== null) {
var wi = tool.getAllWallsAtIntersection(sharedEndpoint);
var endpointHasNonColinearWall_1 = false;
wi.iterator.each(function (w) {
if (!tool.areWallsParallel(w, wa)) {
endpointHasNonColinearWall_1 = true;
}
});
if (!endpointHasNonColinearWall_1) {
isColinear = true;
}
}
}
return isColinear;
};
WallReshapingTool.prototype.findAllColinearWalls = function (w, set) {
if (set === null || set === undefined) {
set = new go.Set();
}
set.add(w);
var tool = this;
var diagram = tool.diagram;
var walls = diagram.findNodesByExample({ category: 'WallGroup' });
walls.iterator.each(function (ow) {
if (tool.isWallColinear(w, ow) && set !== undefined && !set.contains(ow)) {
set.add(ow);
tool.findAllColinearWalls(ow, set);
}
});
return set;
};
WallReshapingTool.prototype.joinColinearWalls = function () {
var tool = this;
if (tool.handle === null)
return;
var adorn = tool.handle.part;
var reshapingWall = adorn.adornedPart;
var cw1 = tool.findAllColinearWalls(reshapingWall);
var jw = tool.performColinearWallJoining(cw1, reshapingWall);
if (jw !== null) {
tool.joinedWalls.add(jw);
}
var wallsAtReturnPoint = tool.getAllWallsAtIntersection(tool.returnPoint);
if (wallsAtReturnPoint.count === 2) {
var wallsArr = wallsAtReturnPoint.toArray();
var w1 = wallsArr[0];
var w2 = wallsArr[1];
if (tool.isWallColinear(w1, w2)) {
var cw2 = new go.Set();
cw2.add(w1);
cw2.add(w2);
var jw2 = tool.performColinearWallJoining(cw2, w1);
if (jw2 !== null) {
tool.joinedWalls.add(jw2);
}
}
}
};
WallReshapingTool.prototype.performColinearWallJoining = function (colinearWalls, w) {
var tool = this;
var fp = tool.diagram;
var garbage = new go.Set();
var cwf = colinearWalls.first();
if (cwf === null) {
return null;
}
if (w === undefined) {
w = cwf;
}
var acceptedCategory = cwf.data.category;
colinearWalls.iterator.each(function (cw) {
if (cw.data.category !== acceptedCategory) {
return;
}
});
if (colinearWalls.count > 1) {
var pt1_1 = null;
var pt2_1 = null;
var farthestDist_1 = 0;
var cw2_1 = colinearWalls.copy();
var wallParts_1 = new go.Set();
colinearWalls.iterator.each(function