Move.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. function Move(layer) {
  2. this.layer = layer;
  3. this.moveType = null;
  4. this.currentState = this.layer.currentState;
  5. this.calculateLine = this.layer.calculateLine;
  6. this.calculateElement = this.layer.calculateElement;
  7. //拖拽门或者窗户 等元素
  8. this.draggingSymbol2d = null;
  9. //拖拽门或者窗户的顶点
  10. this.draggingSymbol2dPoint = null;
  11. //移动墙角的时候保存移动点的信息
  12. //this.moveCornerPoint=null;
  13. };
  14. //移动楼梯角
  15. Move.prototype.moveStaircorner = function (stairid, index, newdragPoint) {
  16. if (stairid == null) {
  17. return;
  18. }
  19. this.layer.vectors[stairid].geometry.points[index].x = newdragPoint.x;
  20. this.layer.vectors[stairid].geometry.points[index].y = newdragPoint.y;
  21. var pt = this.layer.vectors[stairid].geometry.points[this.currentState.currentstartlinePointIndex];
  22. this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x;
  23. this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y;
  24. this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex;
  25. var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[stairid].geometry.points);
  26. this.layer.vectors[stairid].geometry.linkedpoints = allpoints.vertical;
  27. this.layer.vectors[stairid].geometry.borderpoints.border1 = allpoints.border1;
  28. this.layer.vectors[stairid].geometry.borderpoints.border2 = allpoints.border2;
  29. this.layer.vectors[stairid].geometry.arrowpoints.arrows1 = allpoints.arrows1;
  30. this.layer.vectors[stairid].geometry.arrowpoints.arrows2 = allpoints.arrows2;
  31. this.layer.control.refreshCanvas = true;
  32. this.layer.control.refreshSelectCanvas = true;
  33. };
  34. Move.prototype.moveSpiralcorner = function (stairId, point, index) {
  35. var center = this.layer.vectors[stairId].geometry.point;
  36. var r = this.layer.parameter.spiralR1;
  37. var line = this.calculateLine.createLine(point, center);
  38. var newpoint = {};
  39. var angle = null;
  40. if (line.hasOwnProperty('x')) {
  41. newpoint.x = center.x;
  42. if (point.y > center.y) {
  43. newpoint.y = center.y + r;
  44. angle = 1.5 * Math.PI;
  45. }
  46. else {
  47. newpoint.y = center.y - r;
  48. angle = Math.PI / 2;
  49. }
  50. }
  51. else if (line.hasOwnProperty('y')) {
  52. newpoint.y = center.y;
  53. if (point.x > center.x) {
  54. newpoint.x = center.x + r;
  55. angle = 0;
  56. }
  57. else {
  58. newpoint.x = center.x - r;
  59. angle = Math.PI;
  60. }
  61. }
  62. else {
  63. var verticalLine1 = {};
  64. var verticalLine2 = {};
  65. verticalLine1.a = -1 / line.a;
  66. verticalLine2.a = -1 / line.a;
  67. var b = center.y - verticalLine1.a * center.x;
  68. verticalLine1.b = b + this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1);
  69. verticalLine2.b = b - this.calculateLine.driftY3(verticalLine1.a, this.layer.parameter.spiralR1);
  70. var join1 = this.calculateLine.getIntersectionPoint(verticalLine1, line);
  71. var join2 = this.calculateLine.getIntersectionPoint(verticalLine2, line);
  72. if (this.calculateLine.containPoint(center, join1, point) || this.calculateLine.containPoint(center, point, join1)) {
  73. newpoint = join1;
  74. }
  75. else {
  76. newpoint = join2;
  77. }
  78. var dx = newpoint.x - center.x;
  79. var dy = newpoint.y - center.y;
  80. if (dx > 0 && dy > 0 || dx < 0 && dy > 0) {
  81. if (line.a > 0) {
  82. angle = 2 * Math.PI - Math.atan(line.a);
  83. }
  84. else {
  85. angle = Math.PI + Math.abs(Math.atan(line.a));
  86. }
  87. }
  88. else {
  89. if (line.a > 0) {
  90. angle = Math.PI - Math.atan(line.a);
  91. }
  92. else {
  93. angle = Math.abs(Math.atan(line.a));
  94. }
  95. }
  96. }
  97. if (index == 1) {
  98. this.layer.vectors[stairId].geometry.sAngle = angle;
  99. this.layer.vectors[stairId].geometry.point1 = newpoint;
  100. }
  101. else {
  102. this.layer.vectors[stairId].geometry.eAngle = angle;
  103. this.layer.vectors[stairId].geometry.point2 = newpoint;
  104. }
  105. this.layer.vectors[this.currentState.currentPointId].geometry.x = newpoint.x;
  106. this.layer.vectors[this.currentState.currentCircleId].geometry.x = newpoint.x;
  107. this.layer.vectors[this.currentState.currentPointId].geometry.y = newpoint.y;
  108. this.layer.vectors[this.currentState.currentCircleId].geometry.y = newpoint.y;
  109. this.layer.control.refreshCanvas = true; this.layer.control.refreshSelectCanvas = true;
  110. };
  111. Move.prototype.moveSpiralPlane = function (stairId, dx, dy) {
  112. var point = {};
  113. point.x = this.layer.vectors[stairId].geometry.point.x + dx;
  114. point.y = this.layer.vectors[stairId].geometry.point.y - dy;
  115. var points = this.calculateElement.GetSpiralpoints(point);
  116. this.layer.vectors[stairId].geometry.point = point;
  117. this.layer.vectors[stairId].geometry.points = points;
  118. this.layer.vectors[stairId].geometry.point1.x += dx;
  119. this.layer.vectors[stairId].geometry.point1.y -= dy;
  120. this.layer.vectors[stairId].geometry.point2.x += dx;
  121. this.layer.vectors[stairId].geometry.point2.y -= dy;
  122. this.layer.control.refreshCanvas = true;
  123. };
  124. //
  125. Move.prototype.endmoveWall = function (newdragPoint) {
  126. };
  127. //移动墙角
  128. //index表示选择的墙角所在的位置
  129. Move.prototype.moveWallcorner = function (wallid, index, newdragPoint) {
  130. if (wallid == null) {
  131. return;
  132. }
  133. var interval = this.layer.parameter.wallThickness;
  134. var len = this.layer.vectors[wallid].geometry.points.length;
  135. delete this.layer.vectors[wallid].geometry.firstLines;
  136. delete this.layer.vectors[wallid].geometry.endLines;
  137. //移动的点与相邻的点是否重合
  138. var flag = false;
  139. for (var i = 0; i < len; ++i) {
  140. if (i != index) {
  141. if (BABYLON.Vector2.Distance(newdragPoint, this.layer.vectors[wallid].geometry.points[i]) < interval) {
  142. flag = true;
  143. //修改data2d的nodes
  144. var index1 = this.calculateElement.getPreIndex(this.layer.vectors[wallid].geometry.points, index);
  145. var index2 = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, index);
  146. if (index1 == i) {
  147. this.layer.data2d.deleteNode({ wallId: wallid, startIndex: index, endIndex: -1 }, index1);
  148. this.layer.data2d.moveNodeForWall({ wallId: wallid, startIndex: index, endIndex: -1 });
  149. }
  150. else if (index2 == i) {
  151. this.layer.data2d.deleteNode({ wallId: wallid, startIndex: index, endIndex: -1 }, index2);
  152. this.layer.data2d.moveNodeForWall({ wallId: wallid, startIndex: index, endIndex: -1 });
  153. }
  154. this.calculateElement.updateSymbolsWallCornerIndexDelete(wallid, i, index)
  155. if (index > i && (index - i) != len - 1) {
  156. this.layer.vectors[wallid].geometry.wallInfo[i].thick = this.layer.vectors[wallid].geometry.wallInfo[index].thick;
  157. this.layer.vectors[wallid].geometry.wallInfo[i].height = this.layer.vectors[wallid].geometry.wallInfo[index].height;
  158. }
  159. this.layer.vectors[wallid].geometry.points.splice(index, 1);
  160. this.layer.vectors[wallid].geometry.wallInfo.splice(index, 1);
  161. if (Math.abs(index - i) == len - 1) {
  162. this.layer.vectors[wallid].geometry.state = 0;
  163. }
  164. if (this.layer.vectors[wallid].geometry.points.length == 1) {
  165. this.layer.data2d.deleteWallid(this.currentState.currentWallId);
  166. this.layer.deleteVector(wallid);
  167. this.layer.select.clearSelect();
  168. this.currentState.selectWallSet = null;
  169. this.currentState.currentWallId = null;
  170. this.layer.control.refreshCanvas = true;
  171. this.layer.pan.f_draggingWallCorner = false;
  172. return;
  173. }
  174. else if (this.layer.vectors[wallid].geometry.points.length < 3) {
  175. this.layer.vectors[wallid].geometry.state = 1;
  176. }
  177. if (index > i) {
  178. index = i;
  179. }
  180. else if (index == 0 && (i == len - 1)) {
  181. //删除了一个点
  182. index = len - 2;
  183. }
  184. this.currentState.currentstartlinePointIndex = index;
  185. break;
  186. }
  187. }
  188. }
  189. if (!flag) {
  190. }
  191. this.layer.vectors[wallid].geometry.points[index].x = newdragPoint.x;
  192. this.layer.vectors[wallid].geometry.points[index].y = newdragPoint.y;
  193. //this.layer.data2d.moveNodeForWall({wallId:wallid,startIndex:index,endIndex:-1});
  194. //处理墙上的门、窗等元素
  195. if (this.layer.vectors[wallid].symbol2dsCount > 0) {
  196. this.moveSymbolsWithWallCorner(wallid, index);
  197. }
  198. //处理选中的图形
  199. this.changeCorner();
  200. this.layer.control.refreshCanvas = true;
  201. this.layer.control.refreshSelectCanvas = true;
  202. };
  203. //改变扇形、圆、点
  204. Move.prototype.changeCorner = function () {
  205. //改变样式:扇形、圆圈等
  206. var pt = this.layer.vectors[this.currentState.currentWallId].geometry.points[this.currentState.currentstartlinePointIndex];
  207. this.layer.vectors[this.currentState.currentPointId].geometry.x = pt.x;
  208. this.layer.vectors[this.currentState.currentPointId].geometry.y = pt.y;
  209. this.layer.vectors[this.currentState.currentPointId].geometry.contextIndex = this.layer.select.contextIndex;
  210. this.layer.vectors[this.currentState.currentCircleId].geometry.x = pt.x;
  211. this.layer.vectors[this.currentState.currentCircleId].geometry.y = pt.y;
  212. this.layer.vectors[this.currentState.currentCircleId].geometry.contextIndex = this.layer.select.contextIndex;
  213. var sector = this.layer.select.editSector(this.currentState.currentstartlinePointIndex);
  214. if (sector != null) {
  215. if (this.currentState.currentSecotrId != null) {
  216. this.layer.vectors[this.currentState.currentSecotrId].geometry.x = sector.x;
  217. this.layer.vectors[this.currentState.currentSecotrId].geometry.y = sector.y;
  218. this.layer.vectors[this.currentState.currentSecotrId].geometry.startAngle = sector.start;
  219. this.layer.vectors[this.currentState.currentSecotrId].geometry.endAngle = sector.end;
  220. this.layer.vectors[this.currentState.currentSecotrId].geometry.contextIndex = this.layer.select.contextIndex;
  221. }
  222. else {
  223. //添加扇形
  224. var addsector = new Sector(sector.x, sector.y, Sector_r, sector.start, sector.end);
  225. var vector = new Vector(addsector, sectorStyle);
  226. this.currentState.currentSecotrId = vector.id;
  227. vector.geometry.contextIndex = this.layer.select.contextIndex;
  228. this.layer.drawSingleVector(vector);
  229. }
  230. }
  231. else {
  232. this.layer.deleteVector(this.currentState.currentSecotrId);
  233. this.currentState.currentSecotrId = null;
  234. }
  235. this.layer.control.refreshSelectCanvas = true;
  236. };
  237. Move.prototype.moveStairLine = function (id, dx, dy, startIndex, endIndex) {
  238. this.layer.vectors[id].geometry.points[startIndex].x += dx * this.layer.res;
  239. this.layer.vectors[id].geometry.points[startIndex].y -= dy * this.layer.res;
  240. this.layer.vectors[id].geometry.points[endIndex].x += dx * this.layer.res;
  241. this.layer.vectors[id].geometry.points[endIndex].y -= dy * this.layer.res;
  242. //移动选中的点和线
  243. if (this.currentState.currentLineId != null) {
  244. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x += dx * this.layer.res;
  245. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x += dx * this.layer.res;
  246. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y -= dy * this.layer.res;
  247. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y -= dy * this.layer.res;
  248. }
  249. if (this.currentState.currentLinePoint1Id != null) {
  250. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x += dx * this.layer.res;
  251. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y -= dy * this.layer.res;
  252. }
  253. if (this.currentState.currentLinePoint2Id != null) {
  254. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x += dx * this.layer.res;
  255. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y -= dy * this.layer.res;
  256. }
  257. var allpoints = this.calculateElement.getAllPointsFromStair(this.layer.vectors[id].geometry.points);
  258. this.layer.vectors[id].geometry.linkedpoints = allpoints.vertical;
  259. this.layer.vectors[id].geometry.borderpoints.border1 = allpoints.border1;
  260. this.layer.vectors[id].geometry.borderpoints.border2 = allpoints.border2;
  261. this.layer.vectors[id].geometry.arrowpoints.arrows1 = allpoints.arrows1;
  262. this.layer.vectors[id].geometry.arrowpoints.arrows2 = allpoints.arrows2;
  263. this.layer.control.refreshSelectCanvas = true;
  264. this.layer.control.refreshCanvas = true;
  265. this.layer.renderer.autoRedraw();
  266. };
  267. /*
  268. //移动楼梯面
  269. Move.prototype.moveStairLine=function(id,dx,dy,startIndex,endIndex)
  270. {
  271. if(id==null||startIndex==null||endIndex==null)
  272. {
  273. return;
  274. }
  275. var r=this.layer.parameter.stairWidth;
  276. var len=this.layer.vectors[id].geometry.points.length;
  277. if(len==2)
  278. {
  279. for(var i=0;i<this.layer.vectors[id].geometry.points.length;++i)
  280. {
  281. var x=this.layer.vectors[id].geometry.points[i].x+dx * this.layer.res;
  282. var y=this.layer.vectors[id].geometry.points[i].y-dy * this.layer.res;
  283. this.layer.vectors[id].geometry.points[i]={x:x,y:y};
  284. }
  285. //移动选中的点和线
  286. if(this.currentState.currentLineId!=null)
  287. {
  288. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x+=dx * this.layer.res;
  289. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x+=dx * this.layer.res;
  290. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y-=dy * this.layer.res;
  291. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y-=dy * this.layer.res;
  292. }
  293. if(this.currentState.currentLinePoint1Id!=null)
  294. {
  295. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x+=dx * this.layer.res;
  296. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y-=dy * this.layer.res;
  297. }
  298. if(this.currentState.currentLinePoint2Id!=null)
  299. {
  300. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x+=dx * this.layer.res;
  301. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y-=dy * this.layer.res;
  302. }
  303. }
  304. else
  305. {
  306. var newdragline=[];
  307. var currentPoint1={};
  308. currentPoint1.x=this.layer.vectors[id].geometry.points[startIndex].x;
  309. currentPoint1.y=this.layer.vectors[id].geometry.points[startIndex].y;
  310. var currentPoint2={};
  311. currentPoint2.x=this.layer.vectors[id].geometry.points[endIndex].x;
  312. currentPoint2.y=this.layer.vectors[id].geometry.points[endIndex].y;
  313. //不考虑周围的墙,鼠标移动后,选中的墙本应该在的位置
  314. newdragline.push({x:currentPoint1.x+ dx * this.layer.res,y:currentPoint1.y- dy * this.layer.res});
  315. newdragline.push({x:currentPoint2.x+ dx * this.layer.res,y:currentPoint2.y- dy * this.layer.res});
  316. var origin=this.layer.calculateElement.getOrginLine(len,id,startIndex,endIndex);
  317. //得到挨着startIndex但不是newdragline的墙的线段
  318. var orginLine1=origin.line1;
  319. //线段的另一个端点
  320. var orginPoint1=this.layer.vectors[id].geometry.points[origin.point1];
  321. //得到挨着endIndex但不是newdragline的墙的线段
  322. var orginLine2=origin.line2;
  323. //线段的另一个端点
  324. var orginPoint2=this.layer.vectors[id].geometry.points[origin.point2];
  325. var newline=this.calculateLine.createLine(newdragline[0],newdragline[1]);
  326. var point1=this.layer.vectors[id].geometry.points[orginLine1[0]];
  327. var point2=this.layer.vectors[id].geometry.points[orginLine1[1]];
  328. //拖拽的墙与挨着的墙的交点
  329. var line1=this.calculateLine.createLine(point1,point2);
  330. var newWallPoint1=this.calculateLine.getIntersectionPoint(line1,newline);
  331. var point3=this.layer.vectors[id].geometry.points[orginLine2[0]];
  332. var point4=this.layer.vectors[id].geometry.points[orginLine2[1]];
  333. //拖拽的墙与另一堵挨着的墙的交点
  334. var line2=this.calculateLine.createLine(point3,point4);
  335. var newWallPoint2=this.calculateLine.getIntersectionPoint(line2,newline);
  336. this.layer.vectors[id].geometry.points[startIndex].x=newWallPoint1.x;
  337. this.layer.vectors[id].geometry.points[startIndex].y=newWallPoint1.y;
  338. this.layer.vectors[id].geometry.points[endIndex].x=newWallPoint2.x;
  339. this.layer.vectors[id].geometry.points[endIndex].y=newWallPoint2.y;
  340. this.currentState.currentstartlinePointIndex=startIndex;
  341. this.currentState.currentendlinePointIndex=endIndex;
  342. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x=newWallPoint1.x;
  343. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y=newWallPoint1.y;
  344. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x=newWallPoint2.x;
  345. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y=newWallPoint2.y;
  346. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x=this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x;
  347. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y=this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y;
  348. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x=this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x;
  349. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y=this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y;
  350. }
  351. var allpoints=this.calculateElement.getAllPointsFromStair(this.layer.vectors[id].geometry.points);
  352. this.layer.vectors[id].geometry.linkedpoints=allpoints.vertical;
  353. this.layer.vectors[id].geometry.borderpoints.border1=allpoints.border1;
  354. this.layer.vectors[id].geometry.borderpoints.border2=allpoints.border2;
  355. this.layer.control.refreshSelectCanvas=true;
  356. this.layer.control.refreshCanvas=true;
  357. this.layer.renderer.autoRedraw();
  358. };
  359. */
  360. //移动整面墙
  361. //startIndex,endIndex表示墙的两个端点
  362. //id表示当前移动墙的id
  363. //dx,dy表示偏移量
  364. Move.prototype.moveWallLine = function (id, dx, dy, startIndex, endIndex) {
  365. if (id == null || startIndex == null || endIndex == null) {
  366. return;
  367. }
  368. var r;
  369. if (this.layer.vectors[id].geometry.wallType == 1) {
  370. r = wallThickness / 2
  371. }
  372. else {
  373. r = partitionThickness / 2
  374. }
  375. var len = this.layer.vectors[id].geometry.points.length;
  376. var newdragline = [];
  377. var currentPoint1 = {};
  378. currentPoint1.x = this.layer.vectors[id].geometry.points[startIndex].x;
  379. currentPoint1.y = this.layer.vectors[id].geometry.points[startIndex].y;
  380. var currentPoint2 = {};
  381. currentPoint2.x = this.layer.vectors[id].geometry.points[endIndex].x;
  382. currentPoint2.y = this.layer.vectors[id].geometry.points[endIndex].y;
  383. //不考虑周围的墙,鼠标移动后,选中的墙本应该在的位置
  384. newdragline.push({ x: currentPoint1.x + dx * this.layer.res, y: currentPoint1.y - dy * this.layer.res });
  385. newdragline.push({ x: currentPoint2.x + dx * this.layer.res, y: currentPoint2.y - dy * this.layer.res });
  386. //如果墙不是闭合的,就拖拽vector就行
  387. if (this.layer.vectors[id].geometry.state == 1) {
  388. for (var i = 0; i < this.layer.vectors[id].geometry.points.length; ++i) {
  389. var x = this.layer.vectors[id].geometry.points[i].x + dx * this.layer.res;
  390. var y = this.layer.vectors[id].geometry.points[i].y - dy * this.layer.res;
  391. this.layer.vectors[id].geometry.points[i] = { x: x, y: y };
  392. }
  393. //移动选中的点和线
  394. if (this.currentState.currentLineId != null) {
  395. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x += dx * this.layer.res;
  396. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x += dx * this.layer.res;
  397. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y -= dy * this.layer.res;
  398. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y -= dy * this.layer.res;
  399. }
  400. if (this.currentState.currentLinePoint1Id != null) {
  401. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x += dx * this.layer.res;
  402. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y -= dy * this.layer.res;
  403. }
  404. if (this.currentState.currentLinePoint2Id != null) {
  405. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x += dx * this.layer.res;
  406. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y -= dy * this.layer.res;
  407. }
  408. //移动墙上所有的symbols
  409. for (var key in this.layer.vectors[id].symbol2Ds) {
  410. if (this.layer.vectors[id].symbol2Ds[key].geometry.geoType != "OpenDoor" && this.layer.vectors[id].symbol2Ds[key].geometry.geoType != "OpenWindow") {
  411. for (var i = 0; i < this.layer.vectors[id].symbol2Ds[key].geometry.points.length; ++i) {
  412. this.layer.vectors[id].symbol2Ds[key].geometry.points[i].x += dx * this.layer.res;
  413. this.layer.vectors[id].symbol2Ds[key].geometry.points[i].y -= dy * this.layer.res;
  414. }
  415. }
  416. this.layer.vectors[id].symbol2Ds[key].geometry.point1.x += dx * this.layer.res;
  417. this.layer.vectors[id].symbol2Ds[key].geometry.point1.y -= dy * this.layer.res;
  418. this.layer.vectors[id].symbol2Ds[key].geometry.point2.x += dx * this.layer.res;
  419. this.layer.vectors[id].symbol2Ds[key].geometry.point2.y -= dy * this.layer.res;
  420. }
  421. this.layer.control.refreshSelectCanvas = true;
  422. this.layer.control.refreshCanvas = true;
  423. this.layer.renderer.autoRedraw();
  424. return;
  425. }
  426. //判断墙中的点有没有合并
  427. var symbolFlag = false;
  428. var flag = false;
  429. var orginLine = [];
  430. var origin = this.layer.calculateElement.getOrginLine(len, id, startIndex, endIndex);
  431. //得到挨着startIndex但不是newdragline的墙的线段
  432. var orginLine1 = origin.line1;
  433. //线段的另一个端点
  434. var orginPoint1 = this.layer.vectors[id].geometry.points[origin.point1];
  435. //得到挨着endIndex但不是newdragline的墙的线段
  436. var orginLine2 = origin.line2;
  437. //线段的另一个端点
  438. var orginPoint2 = this.layer.vectors[id].geometry.points[origin.point2];
  439. var newline = this.calculateLine.createLine(newdragline[0], newdragline[1]);
  440. var point1 = this.layer.vectors[id].geometry.points[orginLine1[0]];
  441. var point2 = this.layer.vectors[id].geometry.points[orginLine1[1]];
  442. //拖拽的墙与挨着的墙的交点
  443. var line1 = this.calculateLine.createLine(point1, point2);
  444. var newWallPoint1 = this.calculateLine.getIntersectionPoint(line1, newline);
  445. var point3 = this.layer.vectors[id].geometry.points[orginLine2[0]];
  446. var point4 = this.layer.vectors[id].geometry.points[orginLine2[1]];
  447. //拖拽的墙与另一堵挨着的墙的交点
  448. var line2 = this.calculateLine.createLine(point3, point4);
  449. var newWallPoint2 = this.calculateLine.getIntersectionPoint(line2, newline);
  450. this.layer.vectors[id].geometry.points[startIndex].x = newWallPoint1.x;
  451. this.layer.vectors[id].geometry.points[startIndex].y = newWallPoint1.y;
  452. this.layer.vectors[id].geometry.points[endIndex].x = newWallPoint2.x;
  453. this.layer.vectors[id].geometry.points[endIndex].y = newWallPoint2.y;
  454. this.currentState.currentstartlinePointIndex = startIndex;
  455. this.currentState.currentendlinePointIndex = endIndex;
  456. this.layer.control.refreshCanvas = true;
  457. if (BABYLON.Vector2.Distance(orginPoint1, newWallPoint1) < 2 * r) {
  458. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x = orginPoint1.x;
  459. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y = orginPoint1.y;
  460. newWallPoint1.x = orginPoint1.x;
  461. newWallPoint1.y = orginPoint1.y;
  462. var indexs = this.calculateElement.updateSelectWallLineIndex(id, startIndex, endIndex, origin.point1);
  463. if (this.calculateElement.isNeighbor(len, origin.point1, startIndex)) {
  464. if (startIndex > origin.point1 && (startIndex - origin.point1) != len - 1) {
  465. this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick;
  466. this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height;
  467. }
  468. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  469. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  470. origin.point1 = Math.min(origin.point1, startIndex);
  471. }
  472. else {
  473. if (endIndex > origin.point1 && (endIndex - origin.point1) != len - 1) {
  474. this.layer.vectors[id].geometry.wallInfo[origin.point1].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick;
  475. this.layer.vectors[id].geometry.wallInfo[origin.point1].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height;
  476. }
  477. this.layer.vectors[id].geometry.points.splice(endIndex, 1);
  478. this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1);
  479. origin.point1 = Math.min(origin.point1, endIndex);
  480. }
  481. startIndex = indexs.wallindex1;
  482. endIndex = indexs.wallindex2;
  483. this.currentState.currentstartlinePointIndex = startIndex;
  484. this.currentState.currentendlinePointIndex = endIndex;
  485. if (this.layer.vectors[id].geometry.points.length < 3) {
  486. this.layer.vectors[id].geometry.state = 1;
  487. }
  488. symbolFlag = true;
  489. }
  490. else if (this.currentState.currentLinePoint1Id != null) {
  491. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x = newWallPoint1.x;
  492. this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y = newWallPoint1.y;
  493. }
  494. if (BABYLON.Vector2.Distance(orginPoint2, newWallPoint2) < 2 * r) {
  495. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = orginPoint2.x;
  496. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = orginPoint2.y;
  497. newWallPoint2.x = orginPoint2.x;
  498. newWallPoint2.y = orginPoint2.y;
  499. var indexs = this.calculateElement.updateSelectWallLineIndex(id, startIndex, endIndex, origin.point2);
  500. if (this.calculateElement.isNeighbor(len, origin.point2, startIndex)) {
  501. if (startIndex > origin.point2 && (startIndex - origin.point2) != len - 1) {
  502. this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[startIndex].thick;
  503. this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[startIndex].height;
  504. }
  505. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  506. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  507. origin.point2 = Math.min(origin.point1, startIndex);
  508. }
  509. else {
  510. if (endIndex > origin.point2 && (endIndex - origin.point2) != len - 1) {
  511. this.layer.vectors[id].geometry.wallInfo[origin.point2].thick = this.layer.vectors[id].geometry.wallInfo[endIndex].thick;
  512. this.layer.vectors[id].geometry.wallInfo[origin.point2].height = this.layer.vectors[id].geometry.wallInfo[endIndex].height;
  513. }
  514. this.layer.vectors[id].geometry.points.splice(endIndex, 1);
  515. this.layer.vectors[id].geometry.wallInfo.splice(endIndex, 1);
  516. origin.point2 = Math.min(origin.point1, endIndex);
  517. }
  518. startIndex = indexs.wallindex1;
  519. endIndex = indexs.wallindex2;
  520. this.currentState.currentstartlinePointIndex = startIndex;
  521. this.currentState.currentendlinePointIndex = endIndex;
  522. if (this.layer.vectors[id].geometry.points.length < 3) {
  523. this.layer.vectors[id].geometry.state = 1;
  524. }
  525. symbolFlag = true;
  526. }
  527. else if (this.currentState.currentLinePoint2Id != null) {
  528. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x = newWallPoint2.x;
  529. this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y = newWallPoint2.y;
  530. }
  531. if (this.layer.vectors[id].geometry.points.length == 1) {
  532. this.layer.data2d.deleteWallid(this.currentState.currentWallId);
  533. this.layer.deleteVector(id);
  534. this.layer.select.clearSelect();
  535. this.currentState.selectWallSet = null;
  536. this.currentState.currentWallId = null;
  537. this.layer.control.refreshCanvas = true;
  538. this.layer.pan.f_draggingWallLine = false;
  539. return;
  540. }
  541. if (this.layer.vectors[id].geometry.points.length == 1 || BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) {
  542. this.layer.select.clearSelect();
  543. this.layer.select.endSelectWallLine();
  544. this.layer.pan.f_draggingWallLine = false;
  545. this.layer.pan.f_draggingWallCorner = true;
  546. var index = startIndex;
  547. if (this.layer.vectors[id].geometry.points.length != 1) {
  548. if (index == this.layer.vectors[id].geometry.points.length - 1) {
  549. index = 0;
  550. }
  551. this.calculateElement.updateSymbolsWallCornerIndexDelete(id, startIndex, endIndex);
  552. this.layer.vectors[id].geometry.points.splice(startIndex, 1);
  553. this.layer.vectors[id].geometry.wallInfo.splice(startIndex, 1);
  554. this.layer.select.selectWallCorner(id, index);
  555. }
  556. else {
  557. index = 0;
  558. this.layer.deleteVector(id);
  559. this.currentState.currentWallId = null;
  560. }
  561. }
  562. if (this.currentState.currentLineId != null) {
  563. if (BABYLON.Vector2.Distance(newWallPoint1, newWallPoint2) < 2 * r) {
  564. this.layer.select.clearSelect();
  565. this.layer.select.selectWallCorner(id, startIndex);
  566. }
  567. else {
  568. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].x = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.x;
  569. this.layer.vectors[this.currentState.currentLineId].geometry.points[0].y = this.layer.vectors[this.currentState.currentLinePoint1Id].geometry.y;
  570. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].x = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.x;
  571. this.layer.vectors[this.currentState.currentLineId].geometry.points[1].y = this.layer.vectors[this.currentState.currentLinePoint2Id].geometry.y;
  572. }
  573. }
  574. this.layer.control.refreshSelectCanvas = true;
  575. //计算改变的像素值
  576. dx = ((newWallPoint1.x - currentPoint1.x) + (newWallPoint2.x - currentPoint2.x)) / 2;
  577. dy = ((newWallPoint1.y - currentPoint1.y) + (newWallPoint2.y - currentPoint2.y)) / 2;
  578. this.moveSymbolsWithWallLine(id, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, dx, dy, symbolFlag);
  579. this.layer.control.refreshCanvas = true;
  580. this.layer.renderer.autoRedraw();
  581. };
  582. //拖拽虚拟的Symbol,point在墙内
  583. Move.prototype.moveVirtualSymbol1 = function (symbol, point) {
  584. var len = symbol.getSymbolLen();
  585. symbol.geometry.r = len;
  586. var wallid = this.currentState.currentWallId;
  587. //获取symbol端点
  588. var endpoint = this.calculateElement.getSymbolEndPoint(point, wallid, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, len);
  589. //选择canvas
  590. symbol.geometry.contextIndex = this.layer.parameter.selectcontext;
  591. symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  592. //更新端点
  593. if (endpoint != null) {
  594. symbol.geometry.point1 = endpoint.newpoint1;
  595. symbol.geometry.point2 = endpoint.newpoint2;
  596. }
  597. if (symbol.geometry.point1 != null & symbol.geometry.point2 != null) {
  598. symbol.update(this.layer, this.currentState.currentWallId, this.currentState.currentstartlinePointIndex, this.currentState.currentendlinePointIndex, point);
  599. if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") {
  600. this.layer.select.selectSymbol(symbol);
  601. }
  602. //更新选中的线和两个圆圈的坐标
  603. else {
  604. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x;
  605. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y;
  606. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x;
  607. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y;
  608. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1;
  609. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2;
  610. }
  611. this.layer.control.refreshSelectCanvas = true;
  612. }
  613. };
  614. //拖拽虚拟的Symbol,point在墙外
  615. Move.prototype.moveVirtualSymbol2 = function (symbol, point) {
  616. var len = symbol.getSymbolLen();
  617. symbol.geometry.thick = this.layer.vectors[symbol.attributes.wallId].geometry.wallInfo[symbol.attributes.wallstartindex].thick;
  618. var endpoint = this.calculateElement.getSymbolEndPoint2(point, symbol.attributes.wallId, symbol.attributes.wallstartindex, symbol.attributes.wallendindex, len);
  619. if (endpoint == null) {
  620. return false;
  621. }
  622. else {
  623. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  624. //更新端点
  625. symbol.geometry.point1 = endpoint.newpoint1;
  626. symbol.geometry.point2 = endpoint.newpoint2;
  627. var newPoint = { x: (endpoint.newpoint1.x + endpoint.newpoint2.x) / 2, y: (endpoint.newpoint1.y + endpoint.newpoint2.y) / 2 };
  628. symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType;
  629. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point);
  630. symbol.geometry.points = this.calculateElement.getSymbolPoints(endpoint.newpoint1, endpoint.newpoint2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  631. this.layer.control.refreshCanvas = true;
  632. }
  633. if (typeof (this.layer.select.selectSymbolIds.selects) == "undefined") {
  634. this.layer.select.selectSymbol(symbol);
  635. }
  636. //更新选中的线和两个圆圈的坐标
  637. else {
  638. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.x = symbol.geometry.point1.x;
  639. this.layer.vectors[this.layer.select.selectSymbolIds.selects[1]].geometry.y = symbol.geometry.point1.y;
  640. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.x = symbol.geometry.point2.x;
  641. this.layer.vectors[this.layer.select.selectSymbolIds.selects[2]].geometry.y = symbol.geometry.point2.y;
  642. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = symbol.geometry.point1;
  643. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = symbol.geometry.point2;
  644. }
  645. this.layer.control.refreshSelectCanvas = true;
  646. return true;
  647. };
  648. //拖拽已经存在的Symbol
  649. Move.prototype.moveExistSymbol = function (lastpoint, point, id) {
  650. var symbol = this.layer.vectors[id];
  651. var wallid = symbol.attributes.wallId;
  652. var startIndex = this.currentState.currentstartlinePointIndex;
  653. var endIndex = this.currentState.currentendlinePointIndex;
  654. symbol.geometry.thick = this.layer.vectors[wallid].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  655. var point1, point2;
  656. var joinpoint = null;
  657. point1 = this.layer.vectors[wallid].geometry.points[startIndex];
  658. if (endIndex != null && typeof (endIndex) != undefined) {
  659. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  660. }
  661. else {
  662. endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state);
  663. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  664. }
  665. this.currentState.selectWallSet = this.calculateElement.wallsContain(point);
  666. if (this.currentState.selectWallSet != null) {
  667. //当前点在墙角
  668. if (this.currentState.selectWallSet.type == 0) {
  669. if (wallid != this.currentState.currentWallId) {
  670. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  671. this.currentState.currentendlinePointIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, this.currentState.selectWallSet.index, this.layer.vectors[wallid].geometry.state);
  672. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  673. wallid = this.currentState.currentWallId;
  674. startIndex = this.currentState.currentstartlinePointIndex;
  675. endIndex = this.currentState.currentendlinePointIndex;
  676. point1 = this.layer.vectors[wallid].geometry.points[startIndex];
  677. if (endIndex) {
  678. point2 = this.layer.vectors[wallid].geometry.points[endIndex];
  679. }
  680. else {
  681. endIndex = this.calculateElement.getNextIndex(this.layer.vectors[wallid].geometry.points, startIndex, this.layer.vectors[wallid].geometry.state);
  682. }
  683. }
  684. //同一组墙,但是墙角不属于当前墙面
  685. else if (this.currentState.selectWallSet.index != endIndex && this.currentState.selectWallSet.index != startIndex) {
  686. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  687. this.currentState.currentendlinePointIndex = endIndex;
  688. }
  689. }
  690. //当前点在墙面
  691. else if (this.currentState.selectWallSet.type == 1) {
  692. this.currentState.currentendlinePointIndex = this.currentState.selectWallSet.endindex;
  693. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  694. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  695. wallid = this.currentState.currentWallId;
  696. startIndex = this.currentState.currentstartlinePointIndex;
  697. endIndex = this.currentState.currentendlinePointIndex;
  698. point1 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.index];
  699. point2 = this.layer.vectors[wallid].geometry.points[this.currentState.selectWallSet.endindex];
  700. }
  701. else {
  702. alert("Move:618");
  703. }
  704. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, point);
  705. }
  706. else {
  707. var line = this.calculateLine.createLine(point1, point2);
  708. joinpoint = { x: point.x, y: point.y };
  709. point = this.calculateLine.getJoinLinePoint(point, line);
  710. if (!this.calculateElement.lineContain(point1, point2, point, 1)) {
  711. return;
  712. }
  713. symbol.attributes.toward = this.calculateLine.getToward(symbol.geometry.point1, symbol.geometry.point2, joinpoint);
  714. }
  715. var symbolLength = symbol.getSymbolLen();
  716. if (BABYLON.Vector2.Distance(point1, point) < symbolLength / 2 || BABYLON.Vector2.Distance(point2, point) < symbolLength / 2) {
  717. return;
  718. }
  719. var sp1 = { x: symbol.geometry.point1.x, y: symbol.geometry.point1.y };
  720. var sp2 = { x: symbol.geometry.point2.x, y: symbol.geometry.point2.y };
  721. this.calculateElement.updateSymbolEndPoint(symbol, point, wallid, startIndex, endIndex);
  722. var dx1 = symbol.geometry.point1.x - sp1.x;
  723. var dy1 = symbol.geometry.point1.y - sp1.y;
  724. var dx2 = symbol.geometry.point2.x - sp2.x;
  725. var dy2 = symbol.geometry.point2.y - sp2.y;
  726. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].x += dx1;
  727. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[0].y += dy1;
  728. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].x += dx2;
  729. this.layer.vectors[symbol.attributes.vectorMeasureid].geometry.points[1].y += dy2;
  730. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  731. symbol.geometry.wallType = this.layer.vectors[symbol.attributes.wallId].geometry.wallType;
  732. symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  733. this.layer.select.f_selectWallLine = false;
  734. this.layer.control.refreshCanvas = true;
  735. this.layer.control.refreshSelectCanvas = true;
  736. };
  737. //移动Symbol上的端点
  738. Move.prototype.moveSymbolEndpoint = function (point, selectindex) {
  739. var wallid = this.draggingSymbol2dPoint.wallid;
  740. var index1 = this.draggingSymbol2dPoint.wallStartindex;
  741. var index2 = this.draggingSymbol2dPoint.wallEndindex;
  742. var selectPoint = this.draggingSymbol2dPoint.selectPoint;
  743. var noselectPoint = this.draggingSymbol2dPoint.noselectPoint;
  744. var mid = { x: (selectPoint.x + noselectPoint.x) / 2, y: (selectPoint.y + noselectPoint.y) / 2 };
  745. var line = this.calculateLine.createLine(this.layer.vectors[wallid].geometry.points[index1], this.layer.vectors[wallid].geometry.points[index2]);
  746. var join = this.calculateLine.getJoinLinePoint(point, line);
  747. var point1 = this.layer.vectors[wallid].geometry.points[index1];
  748. var point2 = this.layer.vectors[wallid].geometry.points[index2];
  749. var dx, dy;
  750. var symbol = this.layer.vectors[this.currentState.currentSymbolId];
  751. if (!this.calculateLine.containPoint(point1, point2, symbol.geometry.point1) || !this.calculateLine.containPoint(point1, point2, symbol.geometry.point2)) {
  752. return;
  753. }
  754. else if (this.calculateLine.containPoint(mid, join, selectPoint) || this.calculateLine.containPoint(mid, selectPoint, join)) {
  755. 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) {
  756. return;
  757. }
  758. if (BABYLON.Vector2.Distance(this.layer.vectors[wallid].geometry.points[index1], join) < symbolMinLen) {
  759. //删除symbol
  760. this.layer.select.endSelectSymbol(this.layer.select.selectSymbolIds.vectorid, this.layer.select.selectSymbolIds.selects, this.layer.select.selectSymbolIds.vectorMeasureid);
  761. this.layer.deleteSymbol(this.currentState.currentSymbolId, wallid);
  762. this.layer.control.refreshCanvas = true;
  763. return;
  764. }
  765. else if (BABYLON.Vector2.Distance(selectPoint, join) < symbolMinLen) {
  766. return;
  767. }
  768. else {
  769. dx = join.x - selectPoint.x;
  770. dy = join.y - selectPoint.y;
  771. noselectPoint.x -= dx;
  772. noselectPoint.y -= dy;
  773. selectPoint.x += dx;
  774. selectPoint.y += dy;
  775. if (this.layer.select.selectSymbolIds.selectEndPointIndex == 1) {
  776. symbol.geometry.point1 = join;
  777. symbol.geometry.point2 = noselectPoint;
  778. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = join.x;
  779. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = join.y;
  780. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = noselectPoint.x;
  781. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = noselectPoint.y;
  782. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = join;
  783. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = noselectPoint;
  784. }
  785. else {
  786. symbol.geometry.point2 = join;
  787. symbol.geometry.point1 = noselectPoint;
  788. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.x = join.x;
  789. this.layer.vectors[this.currentState.currentSymbolCircleId2].geometry.y = join.y;
  790. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.x = noselectPoint.x;
  791. this.layer.vectors[this.currentState.currentSymbolCircleId1].geometry.y = noselectPoint.y;
  792. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[1] = join;
  793. this.layer.vectors[this.layer.select.selectSymbolIds.selects[0]].geometry.points[0] = noselectPoint;
  794. }
  795. var thick = this.layer.getThickness(symbol.attributes.wallId, symbol.attributes.wallstartindex);
  796. symbol.geometry.points = this.calculateElement.getSymbolPoints(symbol.geometry.point1, symbol.geometry.point2, symbol.geometry.geoType, symbol.attributes.toward, thick);
  797. //symbol.geometry.points=this.calculateElement.getSymbolPoints(symbol.geometry.point1,symbol.geometry.point2,symbol.geometry.geoType,point,thick);
  798. this.layer.control.refreshCanvas = true;
  799. this.layer.control.refreshSelectCanvas = true;
  800. }
  801. }
  802. };
  803. //随墙移动
  804. Move.prototype.moveSymbolsWithWallCorner = function (wallid, index) {
  805. var symbol2ds = [];
  806. var movPoint = this.layer.vectors[wallid].geometry.points[index];
  807. var fixPoint = null;
  808. for (var key in this.layer.vectors[wallid].symbol2Ds) {
  809. var symbol2d = this.layer.vectors[wallid].symbol2Ds[key];
  810. if (symbol2d.attributes.wallstartindex == index) {
  811. symbol2ds.push(symbol2d);
  812. fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallendindex];
  813. }
  814. else if (symbol2d.attributes.wallendindex == index) {
  815. symbol2ds.push(symbol2d);
  816. fixPoint = this.layer.vectors[wallid].geometry.points[symbol2d.attributes.wallstartindex];
  817. }
  818. else {
  819. break;
  820. }
  821. if (fixPoint != null) {
  822. var point = this.calculateLine.getNewSymbolPoint(symbol2d, movPoint, fixPoint);
  823. symbol2d.geometry.point1 = point.point1;
  824. symbol2d.geometry.point2 = point.point2;
  825. symbol2d.select = false;
  826. var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex);
  827. symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick);
  828. }
  829. }
  830. this.layer.control.refreshCanvas = true;
  831. };
  832. //随墙移动
  833. Move.prototype.moveSymbolsWithWallLine = function (id, startIndex, endIndex, dx, dy, flag) {
  834. if (typeof (this.layer.vectors[id]) != "undefined" && this.layer.vectors[id].symbol2dsCount > 0) {
  835. for (var key in this.layer.vectors[id].symbol2Ds) {
  836. var newWallPoint1 = this.layer.vectors[id].geometry.points[startIndex];
  837. var newWallPoint2 = this.layer.vectors[id].geometry.points[endIndex];
  838. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  839. if ((symbol2d.attributes.wallstartindex == startIndex && symbol2d.attributes.wallendindex == endIndex) || (symbol2d.attributes.wallstartindex == endIndex && symbol2d.attributes.wallendindex == startIndex)) {
  840. if (!this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point1) || !this.calculateLine.segmentContainPoint(newWallPoint1, newWallPoint2, symbol2d.geometry.point2)) {
  841. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  842. }
  843. else {
  844. var thick = this.layer.getThickness(this.currentState.currentWallId, this.currentState.currentstartlinePointIndex);
  845. if (!flag) {
  846. symbol2d.geometry.point1.x = symbol2d.geometry.point1.x + dx;
  847. symbol2d.geometry.point1.y = symbol2d.geometry.point1.y + dy;
  848. symbol2d.geometry.point2.x = symbol2d.geometry.point2.x + dx;
  849. symbol2d.geometry.point2.y = symbol2d.geometry.point2.y + dy;
  850. symbol2d.select = false;
  851. }
  852. else {
  853. var point = this.calculateLine.getNewSymbolPoint(symbol2d, newWallPoint1, newWallPoint2);
  854. symbol2d.geometry.point1 = point.point1;
  855. symbol2d.geometry.point2 = point.point2;
  856. symbol2d.select = false;
  857. }
  858. symbol2d.geometry.points = this.calculateElement.getSymbolPoints(symbol2d.geometry.point1, symbol2d.geometry.point2, symbol2d.geometry.geoType, symbol2d.attributes.toward, thick);
  859. }
  860. }
  861. else if (symbol2d.attributes.wallstartindex == startIndex || symbol2d.attributes.wallendindex == startIndex) {
  862. if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint1)) {
  863. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  864. }
  865. }
  866. else if (symbol2d.attributes.wallstartindex == endIndex || symbol2d.attributes.wallendindex == endIndex) {
  867. if (this.calculateLine.segmentContainPoint(symbol2d.geometry.point1, symbol2d.geometry.point2, newWallPoint2)) {
  868. this.layer.deleteSymbol(symbol2d.id, symbol2d.attributes.wallId);
  869. }
  870. }
  871. }
  872. }
  873. };
  874. //修改门或窗等元素的index
  875. //id表示墙id
  876. //修改该墙上所有的门、窗等物体
  877. Move.prototype.updateSymbolIndex = function (id, startIndex) {
  878. if (this.layer.vectors[id].symbol2dsCount > 0) {
  879. for (var key in this.layer.vectors[id].symbol2Ds) {
  880. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  881. if (symbol2d.attributes.wallstartindex > startIndex) {
  882. --symbol2d.attributes.wallstartindex;
  883. --this.layer.vectors[symbol2d.vectorid].startindex;
  884. }
  885. else if (symbol2d.attributes.wallstartindex == startIndex) {
  886. if (symbol2d.attributes.wallstartindex != 0) {
  887. --symbol2d.attributes.wallstartindex;
  888. --this.layer.vectors[symbol2d.vectorid].startindex;
  889. }
  890. else {
  891. symbol2d.attributes.wallstartindex = this.layer.vectors[id].geometry.points.length - 2;
  892. this.layer.vectors[symbol2d.vectorid].startindex = this.layer.vectors[id].geometry.points.length - 2;
  893. }
  894. }
  895. }
  896. }
  897. };
  898. //修改该墙上所有的门、窗等物体
  899. Move.prototype.updateSymbolIndex2 = function (id, endIndex) {
  900. if (this.layer.vectors[id].symbol2dsCount > 0) {
  901. for (var key in this.layer.vectors[id].symbol2Ds) {
  902. var symbol2d = this.layer.vectors[id].symbol2Ds[key];
  903. if (symbol2d.attributes.wallstartindex > endIndex) {
  904. --symbol2d.attributes.wallstartindex;
  905. --this.layer.vectors[symbol2d.vectorid].startindex;
  906. }
  907. }
  908. }
  909. };