function Move(layer) { this.layer = layer; this.moveType = null; this.currentState = this.layer.currentState; this.calculateLine = this.layer.calculateLine; this.calculateElement = this.layer.calculateElement; //拖拽门或者窗户 等元素 this.draggingSymbol2d = null; //拖拽门或者窗户的顶点 this.draggingSymbol2dPoint = null; //移动墙角的时候保存移动点的信息 //this.moveCornerPoint=null; }; //移动楼梯角 Move.prototype.moveStaircorner = function (stairid, index, newdragPoint) { if (stairid == null) { return; } this.layer.vectors[stairid].geometry.points[index].x = newdragPoint.x; this.layer.vectors[stairid].geometry.points[index].y = newdragPoint.y; var pt = this.layer.vectors[stairid].geometry.points[this.currentState.currentstartlinePointIndex]; this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x; this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y; this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex; var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[stairid].geometry.points); this.layer.vectors[stairid].geometry.linkedpoints = allpoints.vertical; this.layer.vectors[stairid].geometry.borderpoints.border1 = allpoints.border1; this.layer.vectors[stairid].geometry.borderpoints.border2 = allpoints.border2; this.layer.vectors[stairid].geometry.arrowpoints.arrows1 = allpoints.arrows1; this.layer.vectors[stairid].geometry.arrowpoints.arrows2 = allpoints.arrows2; this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true; }; Move.prototype.moveSpiralcorner = function (stairId, point, index) { var center = this.layer.vectors[stairId].geometry.point; var r = this.layer.parameter.spiralR1; var line = this.calculateLine.createLine(point, center); var newpoint = {}; var angle = null; if (line.hasOwnProperty('x')) { newpoint.x = center.x; if (point.y > center.y) { newpoint.y = center.y + r; angle = 1.5 * Math.PI; } else { newpoint.y = center.y - r; angle = Math.PI / 2; } } else if (line.hasOwnProperty('y')) { newpoint.y = center.y; if (point.x > center.x) { newpoint.x = center.x + r; angle = 0; } else { newpoint.x = center.x - r; angle = Math.PI; } } else { var verticalLine1 = {}; var verticalLine2 = {}; verticalLine1.a = -1 / line.a; verticalLine2.a = -1 / line.a; var b = center.y - verticalLine1.a * center.x; verticalLine1.b = b + this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1); verticalLine2.b = b - this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1); var join1 = this.calculateLine.getIntersectionPoint(verticalLine1, line); var join2 = this.calculateLine.getIntersectionPoint(verticalLine2, line); if (this.calculateLine.containPoint(center, join1, point) || this.calculateLine.containPoint(center, point, join1)) { newpoint = join1; } else { newpoint = join2; } var dx = newpoint.x - center.x; var dy = newpoint.y - center.y; if (dx > 0 && dy > 0 || dx < 0 && dy > 0) { if (line.a > 0) { angle = 2 * Math.PI - Math.atan(line.a); } else { angle = Math.PI + Math.abs(Math.atan(line.a)); } } else { if (line.a > 0) { angle = Math.PI - Math.atan(line.a); } else { angle = Math.abs(Math.atan(line.a)); } } } if (index == 1) { this.layer.vectors[stairId].geometry.sAngle = angle; this.layer.vectors[stairId].geometry.point1 = newpoint; } else { this.layer.vectors[stairId].geometry.eAngle = angle; this.layer.vectors[stairId].geometry.point2 = newpoint; } this.layer.vectors[this.currentState.currentPointId].geometry.x = newpoint.x; this.layer.vectors[this.currentState.currentCircleId].geometry.x = newpoint.x; this.layer.vectors[this.currentState.currentPointId].geometry.y = newpoint.y; this.layer.vectors[this.currentState.currentCircleId].geometry.y = newpoint.y; this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true; }; Move.prototype.moveSpiralPlane = function (stairId, dx, dy) { var point = {}; point.x = this.layer.vectors[stairId].geometry.point.x + dx; point.y = this.layer.vectors[stairId].geometry.point.y - dy; var points = this.calculateElement.GetSpiralpoints(point); this.layer.vectors[stairId].geometry.point = point; this.layer.vectors[stairId].geometry.points = points; this.layer.vectors[stairId].geometry.point1.x += dx; this.layer.vectors[stairId].geometry.point1.y -= dy; this.layer.vectors[stairId].geometry.point2.x += dx; this.layer.vectors[stairId].geometry.point2.y -= dy; this.layer.control.refreshCanvas = true; }; // Move.prototype.endmoveWall = function (newdragPoint) { }; //移动墙角 //index表示选择的墙角所在的位置 Move.prototype.moveWallcorner = function (wallid, index, newdragPoint) { if (wallid == null) { return; } var interval = this.layer.parameter.wallThickness; var len = this.layer.vectors[wallid].geometry.points.length; delete this.layer.vectors[wallid].geometry.firstLines; delete this.layer.vectors[wallid].geometry.endLines; //移动的点与相邻的点是否重合 var flag = false; for (var i = 0; i < len; ++i) { if (i != index) { if (BABYLON.Vector2.Distance(newdragPoint, this.layer.vectors[wallid].geometry.points[i]) < interval) { flag = true; //修改data2d的nodes var index1 = this.calculateElement.getPreIndex(this.layer.vectors[wallid].geometry.points, index); var index2 = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, index); if (index1 == i) { this.layer.data2d.deleteNode({ wallId: wallid, startIndex: index, endIndex: -1 }, index1); this.layer.data2d.moveNodeForWall({ wallId: wallid, startIndex: index, endIndex: -1 }); } else if (index2 == i) { this.layer.data2d.deleteNode({ wallId: wallid, startIndex: index, endIndex: -1 }, index2); this.layer.data2d.moveNodeForWall({ wallId: wallid, startIndex: index, endIndex: -1 }); } this.calculateElement.updateSymbolsWallCornerIndexDelete(wallid, i, index) if (index > i && (index - i) != len - 1) { this.layer.vectors[wallid].geometry.wallInfo[i].thick = this.layer.vectors[wallid].geometry.wallInfo[index].thick; this.layer.vectors[wallid].geometry.wallInfo[i].height = this.layer.vectors[wallid].geometry.wallInfo[index].height; } this.layer.vectors[wallid].geometry.points.splice(index, 1); this.layer.vectors[wallid].geometry.wallInfo.splice(index, 1); if (Math.abs(index - i) == len - 1) { this.layer.vectors[wallid].geometry.state = 0; } if (this.layer.vectors[wallid].geometry.points.length == 1) { this.layer.data2d.deleteWallid(this.currentState.currentWallId); this.layer.deleteVector(wallid); this.layer.select.clearSelect(); this.currentState.selectWallSet = null; this.currentState.currentWallId = null; this.layer.control.refreshCanvas = true; this.layer.pan.f_draggingWallCorner = false; return; } else if (this.layer.vectors[wallid].geometry.points.length < 3) { this.layer.vectors[wallid].geometry.state = 1; } if (index > i) { index = i; } else if (index == 0 && (i == len - 1)) { //删除了一个点 index = len - 2; } this.currentState.currentstartlinePointIndex = index; break; } } } if (!flag) { } this.layer.vectors[wallid].geometry.points[index].x = newdragPoint.x; this.layer.vectors[wallid].geometry.points[index].y = newdragPoint.y; //this.layer.data2d.moveNodeForWall({wallId:wallid,startIndex:index,endIndex:-1}); //处理墙上的门、窗等元素 if (this.layer.vectors[wallid].symbol2dsCount > 0) { this.moveSymbolsWithWallCorner(wallid, index); } //处理选中的图形 this.changeCorner(); this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true; }; //改变扇形、圆、点 Move.prototype.changeCorner = function () { //改变样式:扇形、圆圈等 var pt = this.layer.vectors[this.currentState.currentWallId].geometry.points[this.currentState.currentstartlinePointIndex]; this.layer.vectors[this.currentState.currentPointId].geometry.x = pt.x; this.layer.vectors[this.currentState.currentPointId].geometry.y = pt.y; this.layer.vectors[this.currentState.currentPointId].geometry.contextIndex = this.layer.select.contextIndex; this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x; this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y; this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex; var sector = this.layer.select.editSector(this.currentState.currentstartlinePointIndex); if (sector != null) { if (this.currentState.currentSecotrId != null) { this.layer.vectors[this.currentState.currentSecotrId].geometry.x = sector.x; this.layer.vectors[this.currentState.currentSecotrId].geometry.y = sector.y; this.layer.vectors[this.currentState.currentSecotrId].geometry.startAngle = sector.start; this.layer.vectors[this.currentState.currentSecotrId].geometry.endAngle = sector.end; this.layer.vectors[this.currentState.currentSecotrId].geometry.contextIndex = this.layer.select.contextIndex; } else { //添加扇形 var addsector = new Sector(sector.x, sector.y, Sector_r, sector.start, sector.end); var vector = new Vector(addsector, sectorStyle); this.currentState.currentSecotrId = vector.id; vector.geometry.contextIndex = this.layer.select.contextIndex; this.layer.drawSingleVector(vector); } } else { this.layer.deleteVector(this.currentState.currentSecotrId); this.currentState.currentSecotrId = null; } this.layer.control.refreshSelectCanvas = true; }; Move.prototype.moveStairLine = function (id, dx, dy, startIndex, endIndex) { this.layer.vectors[id].geometry.points[startIndex].x += dx * this.layer.res; this.layer.vectors[id].geometry.points[startIndex].y -= dy * this.layer.res; this.layer.vectors[id].geometry.points[endIndex].x += dx * this.layer.res; this.layer.vectors[id].geometry.points[endIndex].y -= dy * this.layer.res; //移动选中的点和线 if (this.currentState.currentLineId != null) { this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x += dx * this.layer.res; this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x += dx * this.layer.res; this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y -= dy * this.layer.res; this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y -= dy * this.layer.res; } if (this.currentState.currentLinePoint1Id != null) { this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x += dx * this.layer.res; this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y -= dy * this.layer.res; } if (this.currentState.currentLinePoint2Id != null) { this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x += dx * this.layer.res; this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y -= dy * this.layer.res; } var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[id].geometry.points); this.layer.vectors[id].geometry.linkedpoints = allpoints.vertical; this.layer.vectors[id].geometry.borderpoints.border1 = allpoints.border1; this.layer.vectors[id].geometry.borderpoints.border2 = allpoints.border2; this.layer.vectors[id].geometry.arrowpoints.arrows1 = allpoints.arrows1; this.layer.vectors[id].geometry.arrowpoints.arrows2 = allpoints.arrows2; this.layer.control.refreshSelectCanvas = true; this.layer.control.refreshCanvas = true; this.layer.renderer.autoRedraw(); }; /* //移动楼梯面 Move.prototype.moveStairLine=function(id,dx,dy,startIndex,endIndex) { if(id==null||startIndex==null||endIndex==null) { return; } var r=this.layer.parameter.stairWidth; var len=this.layer.vectors[id].geometry.points.length; if(len==2) { for(var i=0;i origin.point1 && (startIndex - origin.point1) != len - 1) { this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick; this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height; } this.layer.vectors[id].geometry.points.splice(startIndex, 1); this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1); origin.point1 = Math.min(origin.point1, startIndex); } else { if (endIndex > origin.point1 && (endIndex - origin.point1) != len - 1) { this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick; this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height; } this.layer.vectors[id].geometry.points.splice(endIndex, 1); this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1); origin.point1 = Math.min(origin.point1, endIndex); } startIndex = indexs.wallindex1; endIndex = indexs.wallindex2; this.currentState.currentstartlinePointIndex = startIndex; this.currentState.currentendlinePointIndex = endIndex; if (this.layer.vectors[id].geometry.points.length < 3) { this.layer.vectors[id].geometry.state = 1; } symbolFlag = true; } else if (this.currentState.currentLinePoint1Id != null) { this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x = newWallPoint1.x; this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y = newWallPoint1.y; } if (BABYLON.Vector2.Distance(orginPoint2, newWallPoint2) < 2 * r) { this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = orginPoint2.x; this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = orginPoint2.y; newWallPoint2.x = orginPoint2.x; newWallPoint2.y = orginPoint2.y; var indexs = this.calculateElement.updateSelectWallLineIndex(id, startIndex, endIndex, origin.point2); if (this.calculateElement.isNeighbor(len, origin.point2, startIndex)) { if (startIndex > origin.point2 && (startIndex - origin.point2) != len - 1) { this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick; this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height; } this.layer.vectors[id].geometry.points.splice(startIndex, 1); this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1); origin.point2 = Math.min(origin.point1, startIndex); } else { if (endIndex > origin.point2 && (endIndex - origin.point2) != len - 1) { this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick; this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height; } this.layer.vectors[id].geometry.points.splice(endIndex, 1); this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1); origin.point2 = Math.min(origin.point1, endIndex); } startIndex = indexs.wallindex1; endIndex = indexs.wallindex2; this.currentState.currentstartlinePointIndex = startIndex; this.currentState.currentendlinePointIndex = endIndex; if (this.layer.vectors[id].geometry.points.length < 3) { this.layer.vectors[id].geometry.state = 1; } symbolFlag = true; } else if (this.currentState.currentLinePoint2Id != null) { this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = newWallPoint2.x; this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = newWallPoint2.y; } if (this.layer.vectors[id].geometry.points.length == 1) { this.layer.data2d.deleteWallid(this.currentState.currentWallId); this.layer.deleteVector(id); this.layer.select.clearSelect(); this.currentState.selectWallSet = null; this.currentState.currentWallId = null; this.layer.control.refreshCanvas = true; this.layer.pan.f_draggingWallLine = false; return; } if (this.layer.vectors[id].geometry.points.length == 1 || BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) { this.layer.select.clearSelect(); this.layer.select.endSelectWallLine(); this.layer.pan.f_draggingWallLine = false; this.layer.pan.f_draggingWallCorner = true; var index = startIndex; if (this.layer.vectors[id].geometry.points.length != 1) { if (index == this.layer.vectors[id].geometry.points.length - 1) { index = 0; } this.calculateElement.updateSymbolsWallCornerIndexDelete(id, startIndex, endIndex); this.layer.vectors[id].geometry.points.splice(startIndex, 1); this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1); this.layer.select.selectWallCorner(id, index); } else { index = 0; this.layer.deleteVector(id); this.currentState.currentWallId = null; } } if (this.currentState.currentLineId != null) { if (BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) { this.layer.select.clearSelect(); this.layer.select.selectWallCorner(id, startIndex); } else { this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x; this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y; this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x; this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y; } } this.layer.control.refreshSelectCanvas = true; //计算改变的像素值 dx = ((newWallPoint1.x - currentPoint1.x) + (newWallPoint2.x - currentPoint2.x)) / 2; dy = ((newWallPoint1.y - currentPoint1.y) + (newWallPoint2.y - currentPoint2.y)) / 2; this.moveSymbolsWithWallLine(id, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, dx, dy, symbolFlag); this.layer.control.refreshCanvas = true; this.layer.renderer.autoRedraw(); }; //拖拽虚拟的Symbol,point在墙内 Move.prototype.moveVirtualSymbol1 = function (symbol, point) { var len = symbol.getSymbolLen(); symbol.geometry.r = len; var wallid = this.currentState.currentWallId; //获取symbol端点 var endpoint = this.calculateElement.getSymbolEndPoint(point, wallid, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, len); //选择canvas symbol.geometry.contextIndex = this.layer.parameter.selectcontext; symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick; //更新端点 if (endpoint != null) { symbol.geometry.point1 = endpoint.newpoint1; symbol.geometry.point2 = endpoint.newpoint2; } if (symbol.geometry.point1 != null & symbol.geometry.point2 != null) { symbol.update(this.layer, this.currentState.currentWallId, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, point); if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") { this.layer.select.selectSymbol(symbol); } //更新选中的线和两个圆圈的坐标 else { this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x; this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x; this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2; } this.layer.control.refreshSelectCanvas = true; } }; //拖拽虚拟的Symbol,point在墙外 Move.prototype.moveVirtualSymbol2 = function (symbol, point) { var len = symbol.getSymbolLen(); symbol.geometry.thick = this.layer.vectors[symbol.attributes.wallId].geometry.wallInfo[symbol.attributes.wallstartindex].thick; var endpoint = this.calculateElement.getSymbolEndPoint2(point, symbol.attributes.wallId, symbol.attributes.wallstartindex, symbol.attributes.wallendindex, len); if (endpoint == null) { return false; } else { var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex); //更新端点 symbol.geometry.point1 = endpoint.newpoint1; symbol.geometry.point2 = endpoint.newpoint2; var newPoint = { x: (endpoint.newpoint1.x + endpoint.newpoint2.x) / 2, y: (endpoint.newpoint1.y + endpoint.newpoint2.y) / 2 }; symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType; symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point); symbol.geometry.points = this.calculateElement.getSymbolPoints(endpoint.newpoint1, endpoint.newpoint2, symbol.geometry.geoType, symbol.attributes.toward, thick); this.layer.control.refreshCanvas = true; } if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") { this.layer.select.selectSymbol(symbol); } //更新选中的线和两个圆圈的坐标 else { this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x; this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x; this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2; } this.layer.control.refreshSelectCanvas = true; return true; }; //拖拽已经存在的Symbol Move.prototype.moveExistSymbol = function (lastpoint, point, id) { var symbol = this.layer.vectors[id]; var wallid = symbol.attributes.wallId; var startIndex = this.currentState.currentstartlinePointIndex; var endIndex = this.currentState.currentendlinePointIndex; symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick; var point1, point2; var joinpoint = null; point1 = this.layer.vectors[wallid].geometry.points[startIndex]; if (endIndex != null && typeof (endIndex) != undefined) { point2 = this.layer.vectors[wallid].geometry.points[endIndex]; } else { endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state); point2 = this.layer.vectors[wallid].geometry.points[endIndex]; } this.currentState.selectWallSet = this.calculateElement.wallsContain(point); if (this.currentState.selectWallSet != null) { //当前点在墙角 if (this.currentState.selectWallSet.type == 0) { if (wallid != this.currentState.currentWallId) { this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index; this.currentState.currentendlinePointIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, this.currentState.selectWallSet.index, this.layer.vectors[wallid].geometry.state); this.currentState.currentWallId = this.currentState.selectWallSet.id; wallid = this.currentState.currentWallId; startIndex = this.currentState.currentstartlinePointIndex; endIndex = this.currentState.currentendlinePointIndex; point1 = this.layer.vectors[wallid].geometry.points[startIndex]; if (endIndex) { point2 = this.layer.vectors[wallid].geometry.points[endIndex]; } else { endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state); } } //同一组墙,但是墙角不属于当前墙面 else if (this.currentState.selectWallSet.index != endIndex && this.currentState.selectWallSet.index != startIndex) { this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index; this.currentState.currentendlinePointIndex = endIndex; } } //当前点在墙面 else if (this.currentState.selectWallSet.type == 1) { this.currentState.currentendlinePointIndex = this.currentState.selectWallSet.endindex; this.currentState.currentWallId = this.currentState.selectWallSet.id; this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index; wallid = this.currentState.currentWallId; startIndex = this.currentState.currentstartlinePointIndex; endIndex = this.currentState.currentendlinePointIndex; point1 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.index]; point2 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.endindex]; } else { alert("Move:618"); } symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point); } else { var line = this.calculateLine.createLine(point1, point2); joinpoint = { x: point.x, y: point.y }; point = this.calculateLine.getJoinLinePoint(point, line); if (!this.calculateElement.lineContain(point1, point2, point, 1)) { return; } symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, joinpoint); } var symbolLength = symbol.getSymbolLen(); if (BABYLON.Vector2.Distance(point1, point) < symbolLength / 2 || BABYLON.Vector2.Distance(point2, point) < symbolLength / 2) { return; } var sp1 = { x: symbol.geometry.point1.x, y: symbol.geometry.point1.y }; var sp2 = { x: symbol.geometry.point2.x, y: symbol.geometry.point2.y }; this.calculateElement.updateSymbolEndPoint(symbol, point, wallid, startIndex, endIndex); var dx1 = symbol.geometry.point1.x - sp1.x; var dy1 = symbol.geometry.point1.y - sp1.y; var dx2 = symbol.geometry.point2.x - sp2.x; var dy2 = symbol.geometry.point2.y - sp2.y; this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].x += dx1; this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].y += dy1; this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].x += dx2; this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].y += dy2; var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex); symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType; symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick); this.layer.select.f_selectWallLine = false; this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true; }; //移动Symbol上的端点 Move.prototype.moveSymbolEndpoint = function (point, selectindex) { var wallid = this.draggingSymbol2dPoint.wallid; var index1 = this.draggingSymbol2dPoint.wallStartindex; var index2 = this.draggingSymbol2dPoint.wallEndindex; var selectPoint = this.draggingSymbol2dPoint.selectPoint; var noselectPoint = this.draggingSymbol2dPoint.noselectPoint; var mid = { x: (selectPoint.x + noselectPoint.x) / 2, y: (selectPoint.y + noselectPoint.y) / 2 }; var line = this.calculateLine.createLine(this.layer.vectors[wallid].geometry.points[index1], this.layer.vectors[wallid].geometry.points[index2]); var join = this.calculateLine.getJoinLinePoint(point, line); var point1 = this.layer.vectors[wallid].geometry.points[index1]; var point2 = this.layer.vectors[wallid].geometry.points[index2]; var dx, dy; var symbol = this.layer.vectors[this.currentState.currentSymbolId]; if (!this.calculateLine.containPoint(point1, point2, symbol.geometry.point1) || !this.calculateLine.containPoint(point1, point2, symbol.geometry.point2)) { return; } else if (this.calculateLine.containPoint(mid, join, selectPoint) || this.calculateLine.containPoint(mid, selectPoint, join)) { if (BABYLON.Vector2.Distance(point1, symbol.geometry.point1) < symbolMinLen || BABYLON.Vector2.Distance(point2, symbol.geometry.point1) < symbolMinLen || BABYLON.Vector2.Distance(point1, symbol.geometry.point2) < symbolMinLen || BABYLON.Vector2.Distance(point2, symbol.geometry.point2) < symbolMinLen) { return; } if (BABYLON.Vector2.Distance(this.layer.vectors[wallid].geometry.points[index1], join) < symbolMinLen) { //删除symbol this.layer.select.endSelectSymbol(this.layer.select.selectSymbolIds.vectorid, this.layer.select.selectSymbolIds.selects, this.layer.select.selectSymbolIds.vectorMeasureid); this.layer.deleteSymbol(this.currentState.currentSymbolId, wallid); this.layer.control.refreshCanvas = true; return; } else if (BABYLON.Vector2.Distance(selectPoint, join) < symbolMinLen) { return; } else { dx = join.x - selectPoint.x; dy = join.y - selectPoint.y; noselectPoint.x -= dx; noselectPoint.y -= dy; selectPoint.x += dx; selectPoint.y += dy; if (this.layer.select.selectSymbolIds.selectEndPointIndex == 1) { symbol.geometry.point1 = join; symbol.geometry.point2 = noselectPoint; this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = join.x; this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = join.y; this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = noselectPoint.x; this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = noselectPoint.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = join; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = noselectPoint; } else { symbol.geometry.point2 = join; symbol.geometry.point1 = noselectPoint; this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = join.x; this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = join.y; this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = noselectPoint.x; this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = noselectPoint.y; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = join; this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = noselectPoint; } var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex); symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick); //symbol.geometry.points=this.calculateElement.getSymbolPoints(symbol.geometry.point1,symbol.geometry.point2,symbol.geometry.geoType,point,thick); this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true; } } }; //随墙移动 Move.prototype.moveSymbolsWithWallCorner = function (wallid, index) { var symbol2ds = []; var movPoint = this.layer.vectors[wallid].geometry.points[index]; var fixPoint = null; for (var key in this.layer.vectors[wallid].symbol2Ds) { var symbol2d = this.layer.vectors[wallid].symbol2Ds[key]; if (symbol2d.attributes.wallstartindex == index) { symbol2ds.push(symbol2d); fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallendindex]; } else if (symbol2d.attributes.wallendindex == index) { symbol2ds.push(symbol2d); fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallstartindex]; } else { break; } if (fixPoint != null) { var point = this.calculateLine.getNewSymbolPoint(symbol2d, movPoint, fixPoint); symbol2d.geometry.point1 = point.point1; symbol2d.geometry.point2 = point.point2; symbol2d.select = false; var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex); symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick); } } this.layer.control.refreshCanvas = true; }; //随墙移动 Move.prototype.moveSymbolsWithWallLine = function (id, startIndex, endIndex, dx, dy, flag) { if (typeof (this.layer.vectors[id]) != "undefined" && this.layer.vectors[id].symbol2dsCount > 0) { for (var key in this.layer.vectors[id].symbol2Ds) { var newWallPoint1 = this.layer.vectors[id].geometry.points[startIndex]; var newWallPoint2 = this.layer.vectors[id].geometry.points[endIndex]; var symbol2d = this.layer.vectors[id].symbol2Ds[key]; if ((symbol2d.attributes.wallstartindex == startIndex && symbol2d.attributes.wallendindex == endIndex) || (symbol2d.attributes.wallstartindex == endIndex && symbol2d.attributes.wallendindex == startIndex)) { if (!this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point1) || !this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point2)) { this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId); } else { var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex); if (!flag) { symbol2d.geometry.point1.x = symbol2d.geometry.point1.x + dx; symbol2d.geometry.point1.y = symbol2d.geometry.point1.y + dy; symbol2d.geometry.point2.x = symbol2d.geometry.point2.x + dx; symbol2d.geometry.point2.y = symbol2d.geometry.point2.y + dy; symbol2d.select = false; } else { var point = this.calculateLine.getNewSymbolPoint(symbol2d, newWallPoint1, newWallPoint2); symbol2d.geometry.point1 = point.point1; symbol2d.geometry.point2 = point.point2; symbol2d.select = false; } symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick); } } else if (symbol2d.attributes.wallstartindex == startIndex || symbol2d.attributes.wallendindex == startIndex) { if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint1)) { this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId); } } else if (symbol2d.attributes.wallstartindex == endIndex || symbol2d.attributes.wallendindex == endIndex) { if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint2)) { this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId); } } } } }; //修改门或窗等元素的index //id表示墙id //修改该墙上所有的门、窗等物体 Move.prototype.updateSymbolIndex = function (id, startIndex) { if (this.layer.vectors[id].symbol2dsCount > 0) { for (var key in this.layer.vectors[id].symbol2Ds) { var symbol2d = this.layer.vectors[id].symbol2Ds[key]; if (symbol2d.attributes.wallstartindex > startIndex) { --symbol2d.attributes.wallstartindex; --this.layer.vectors[symbol2d.vectorid].startindex; } else if (symbol2d.attributes.wallstartindex == startIndex) { if (symbol2d.attributes.wallstartindex != 0) { --symbol2d.attributes.wallstartindex; --this.layer.vectors[symbol2d.vectorid].startindex; } else { symbol2d.attributes.wallstartindex = this.layer.vectors[id].geometry.points.length - 2; this.layer.vectors[symbol2d.vectorid].startindex = this.layer.vectors[id].geometry.points.length - 2; } } } } }; //修改该墙上所有的门、窗等物体 Move.prototype.updateSymbolIndex2 = function (id, endIndex) { if (this.layer.vectors[id].symbol2dsCount > 0) { for (var key in this.layer.vectors[id].symbol2Ds) { var symbol2d = this.layer.vectors[id].symbol2Ds[key]; if (symbol2d.attributes.wallstartindex > endIndex) { --symbol2d.attributes.wallstartindex; --this.layer.vectors[symbol2d.vectorid].startindex; } } } };