Pan.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. //CLASS:控制平移。
  2. function Pan(layer) {
  3. this.layer = layer;
  4. this.calculateLine = this.layer.calculateLine;
  5. this.calculateElement = this.layer.calculateElement;
  6. this.div = this.layer.div;
  7. this.currentState = this.layer.currentState;
  8. this.previousState = this.layer.previousState;
  9. this.calculateElement = this.layer.calculateElement;
  10. this.active();
  11. //区分双击和单击
  12. this._doubleclick = false;
  13. //拖拽背景
  14. this.f_draggingBackGround = false;
  15. //拖拽墙
  16. this.f_draggingWallLine = false;
  17. //拖拽楼梯面
  18. this.f_draggingStairLine = false;
  19. //拖拽墙角
  20. this.f_draggingWallCorner = false;
  21. //拖拽楼梯角
  22. this.f_draggingStairCorner = false;
  23. //拖拽门或窗等元素
  24. this.f_draggingSymbol = false;
  25. //拖拽symbol的端点
  26. this.f_draggingEndpoint = false;
  27. //拖拽旋转梯角
  28. this.f_draggingSpiralCorner = false;
  29. //拖拽旋转梯
  30. this.f_draggingSpiralPlane = false;
  31. //修建墙
  32. this.f_buildingWall = false;
  33. //修建隔断
  34. this.f_buildingPartition = false;
  35. //修建直梯
  36. this.f_buildingWinderStair = false;
  37. //修建螺旋梯
  38. this.f_buildingSpiral = false;
  39. //添加symbol,比如:门或者窗户等
  40. this.f_buildingSymbol = false;
  41. //用来判断拖拽函数调用了几次,如果少于2次,则弹出编辑框
  42. this.dragging = { count: 0, type: null };
  43. this.build = this.layer.build;
  44. this.select = this.layer.select;
  45. this.data2d = this.layer.data2d;
  46. this.move = this.layer.move;
  47. this.lastPoint = {};
  48. this.diffX = 0;
  49. this.diffY = 0;
  50. this.addNew();
  51. //控制显示编辑wall
  52. this.editwall = null;
  53. this.ajustEndPointForWall = null;
  54. };
  55. Pan.prototype.startPan = (function() {
  56. var strategy = {
  57. //建立墙或隔断
  58. wall: function (args) {
  59. this.layer.div.style.cursor = "crosshair";
  60. if ((this.build.buildwallState == 1 || this.build.buildwallState == 2) &&
  61. this.currentState.selectWallSet != null
  62. ) {
  63. this.build.buildwallState = null;
  64. var point = this.build.adjustPoint(args.point);
  65. this.build.temp_buildwallId != null && (
  66. this.layer.vectors[this.build.temp_buildwallId].geometry.points[1] = args.point
  67. );
  68. this.build.BuildingWall(point);
  69. this.layer.vectors[this.build.buildwallId].geometry.endLines = this.build.getRelaEndLines();
  70. this.ajustEndPointForWall = this.currentState.selectWallSet.id + ";" + this.build.buildwallId;
  71. this.build.finishWall();
  72. } else { //开始画墙
  73. this.build.buildwallState = 2;
  74. this.build.BuildingWall(args.point);
  75. }
  76. this.layer.control.refreshCanvas = true;
  77. },
  78. WinderStair: function (args) {
  79. this.layer.div.style.cursor = "crosshair";
  80. this.f_buildingWinderStair = true;
  81. if (this.build.buildwallState == 1) {
  82. this.build.buildwallState = 2;
  83. }
  84. this.build.BuildingWinderStair(args.point);
  85. },
  86. Spiral: function (args) {
  87. this.layer.div.style.cursor = "crosshair";
  88. this.build.BuildingSpiral(args.point);
  89. this.currentState.startbuild = null;
  90. },
  91. __default: function (args) {
  92. if (this.layer.build.tryAddSymbol == null) {
  93. this.f_draggingBackGround = false;
  94. this.f_draggingSpiralPlane = false;
  95. this.f_draggingWallCorner = false;
  96. this.f_draggingWallLine = false;
  97. this.f_draggingSpiralCorner = false;
  98. this.f_draggingStairLine = false;
  99. this.f_draggingStairCorner = false;
  100. if (this.currentState.selectWallSet != null) {
  101. this.f_draggingWallCorner = this.currentState.selectWallSet.type == 0; // 当前选择墙角
  102. this.f_draggingWallLine = this.currentState.selectWallSet.type == 1; // 当前选择墙面
  103. } else if (this.currentState.selectStairSet == null) {
  104. this.f_draggingBackGround = true;
  105. } else if (this.currentState.selectStairSet.geoType == "Spiral") {
  106. this.f_draggingSpiralCorner = this.currentState.selectStairSet.type == 0;
  107. this.f_draggingSpiralPlane = this.currentState.selectStairSet.type == 1
  108. } else {
  109. this.f_draggingStairCorner = this.currentState.selectStairSet.type == 0; // 当前选择楼梯角
  110. this.f_draggingStairLine = this.currentState.selectStairSet.type == 0; // 当前选择楼梯面
  111. }
  112. // this.f_draggingBackGround = true;
  113. }
  114. console.log(this.currentState.selectWallSet)
  115. //当前选择墙面
  116. if (this.currentState.selectWallSet != null && this.currentState.selectWallSet.type == 1) {
  117. this.f_draggingBackGround = false;
  118. this.f_draggingWallLine = true;
  119. this.f_draggingWallCorner = false;
  120. this.select.f_selectWallLine = true;
  121. if (this.layer.build.tryAddSymbol != null) {
  122. this.select.convertTrue(this.layer.build.tryAddSymbol);
  123. this.layer.build.tryAddSymbol = null;
  124. this.f_draggingWallLine = false;
  125. } else if (this.select.f_selectSymbol) {
  126. this.f_draggingWallLine = false;
  127. this.f_draggingSymbol = true;
  128. this.select.f_selectWallLine = false;
  129. var symbol2d = this.layer.vectors[this.currentState.currentSymbolId];
  130. //编辑门或窗等元素的大小
  131. if (BABYLON.Vector2.Distance(symbol2d.geometry.point1, args.point) < sysmbolCircleR) {
  132. this.select.selectSymbolIds.selectEndPointIndex = 1;
  133. this.select.selectSymbolPoint(symbol2d, args.point);
  134. this.f_draggingEndpoint = true;
  135. } else if (BABYLON.Vector2.Distance(symbol2d.geometry.point2, args.point) < sysmbolCircleR) {
  136. this.select.selectSymbolIds.selectEndPointIndex = 2;
  137. this.select.selectSymbolPoint(symbol2d, args.point);
  138. this.f_draggingEndpoint = true;
  139. }
  140. } else {
  141. this.dragging.type = "wall";
  142. this.dragging.wallid = this.currentState.selectWallSet.id;
  143. this.dragging.index = this.currentState.selectWallSet.index;
  144. }
  145. }
  146. }
  147. }
  148. return function (e) {
  149. for (var key in strategy) {
  150. strategy[key] = strategy[key].bind(this)
  151. }
  152. strategy.partition = strategy.wall
  153. if (this.layer.control.draggingDialog) {
  154. return;
  155. }
  156. document.getElementById('configuratorWindow2').style.display = "none";
  157. this.currentState.addSymbol = null;
  158. //在一开始保存点击的位置。
  159. this.lastX = (e.offsetX || e.layerX);
  160. this.lastY = (e.offsetY || e.layerY);
  161. var point = this.layer.getPositionFromPx({ x: this.lastX, y: this.lastY });
  162. if (this.currentState.startbuild) {
  163. strategy[this.currentState.startbuild]({point: point})
  164. } else {
  165. strategy.__default({ point: point })
  166. }
  167. //设置鼠标样式。
  168. this.layer.div.style.cursor = "move";
  169. this.layer.renderer.autoRedraw();
  170. CanvasSketch.stopEventBubble(e);
  171. };
  172. })();
  173. // 在canvas上移动各个菜单对应发生的事件
  174. Pan.prototype.pan = function () {
  175. var strategy = {
  176. // 拖拽视图
  177. f_draggingBackGround: function (args) {
  178. this.layer.center.x -= args.dx * this.layer.res;
  179. this.layer.center.y += args.dy * this.layer.res;
  180. this.layer.moveTo(this.layer.zoom, this.layer.center);
  181. },
  182. // 拖拽直梯顶点
  183. f_draggingStairCorner: function (args) {
  184. this.move.moveStaircorner(
  185. this.currentState.currentStairId,
  186. this.currentState.currentstartlinePointIndex,
  187. args.point
  188. );
  189. },
  190. // 拖拽直梯中心线
  191. f_draggingStairLine: function (args) {
  192. this.move.moveStairLine(
  193. this.currentState.currentStairId,
  194. args.dx,
  195. args.dy,
  196. this.currentState.currentstartlinePointIndex,
  197. this.currentState.currentendlinePointIndex
  198. );
  199. },
  200. // 拖拽旋转体
  201. f_draggingSpiralCorner: function (args) {
  202. this.move.moveSpiralcorner(
  203. this.currentState.currentStairId,
  204. args.point,
  205. this.currentState.currentstartlinePointIndex
  206. );
  207. },
  208. // 拖拽螺旋体平面位置
  209. f_draggingSpiralPlane: function (args) {
  210. this.move.moveSpiralPlane(
  211. this.currentState.currentStairId,
  212. args.dx,
  213. args.dy
  214. );
  215. },
  216. // 拖拽墙面的角度
  217. f_draggingWallCorner: function (args) {
  218. this.move.moveWallcorner(
  219. this.currentState.selectWallSet.id,
  220. this.currentState.currentstartlinePointIndex,
  221. args.point
  222. );
  223. },
  224. // 拖拽墙面中心线
  225. f_draggingWallLine: function (args) {
  226. this.move.moveWallLine(
  227. args.wallid,
  228. args.dx,
  229. args.dy,
  230. this.currentState.currentstartlinePointIndex,
  231. this.currentState.currentendlinePointIndex
  232. );
  233. this.dragging.count++
  234. },
  235. // 拖拽设置门窗顶点 设置位置
  236. f_draggingSymbol: function (args) {
  237. this.move.moveExistSymbol(
  238. this.lastPoint,
  239. args.point,
  240. this.currentState.currentSymbolId
  241. );
  242. },
  243. // 拖拽设置门窗顶点 设置长度
  244. f_draggingEndpoint: function (args) {
  245. this.move.moveSymbolEndpoint(args.point);
  246. },
  247. // 其余设置都经过
  248. __default: function (args) {
  249. if (this.f_buildingWall || this.f_buildingPartition) { //修墙
  250. this.build.buildwallState = 1;
  251. this.layer.build.BuildingWall(args.point);
  252. } else if (this.f_buildingWinderStair) { //修楼梯
  253. this.build.buildwallState = 1;
  254. this.layer.build.BuildingWinderStair(args.point);
  255. }
  256. this.previousState.save(this.currentState);
  257. this.currentState.selectStairSet = this.calculateElement.stairsContain(args.point); //判断是否在楼梯上
  258. if (this.currentState.selectStairSet != null &&
  259. this.currentState.addSymbol == null) {
  260. var stairid = this.currentState.selectStairSet.id;
  261. this.layer.vectors[stairid].geometry.geoType == "Spiral" ?
  262. strategy.__selectStairSpiral(args) :
  263. strategy.__selectStair(args)
  264. } else if (this.layer.data2d.wallIds.length > 0) {
  265. //当前点是否在墙上
  266. this.currentState.selectWallSet = this.calculateElement.wallsContain(args.point);
  267. this.currentState.selectWallSet ?
  268. strategy.__selectWallSet(args) :
  269. strategy.__selectNotWallSet(args)
  270. }
  271. },
  272. // 悬停在直梯上
  273. __selectStair: function (args) {
  274. var repeat = this.currentState.isRetain(this.previousState);
  275. if (!repeat) {
  276. this.select.clearSelect();
  277. this.currentState.currentendlinePointIndex = this.currentState.selectStairSet.endindex;
  278. this.currentState.currentStairId = this.currentState.selectStairSet.id;
  279. this.currentState.currentstartlinePointIndex = this.currentState.selectStairSet.index;
  280. }
  281. if (this.currentState.selectStairSet.type == 0) { //当前选择的是楼梯的拐角
  282. //状态变化,选择拐角
  283. repeat || this.select.selectStairCorner(
  284. this.currentState.selectStairSet.id,
  285. this.currentState.selectStairSet.index
  286. );
  287. } else if (this.currentState.selectStairSet.type == 1) { //当前选择的是楼梯面
  288. repeat || (this.select.f_selectStairLine = true)
  289. if (this.select.f_selectStairLine && this.currentState.currentLineId == null) {
  290. this.select.selectStairWallLine(
  291. this.currentState.currentStairId,
  292. this.currentState.currentstartlinePointIndex,
  293. this.currentState.currentendlinePointIndex
  294. );
  295. }
  296. }
  297. },
  298. // 悬停在螺旋梯形上
  299. __selectStairSpiral: function (args) {
  300. var stairid = this.currentState.selectStairSet.id;
  301. var repeat = this.previousState.type == this.currentState.selectStairSet.type &&
  302. this.previousState.currentStairId == stairid;
  303. if (!repeat) {
  304. if (this.currentState.selectStairSet.type == 0) {
  305. this.select.endselectSpiralPlane();
  306. this.select.selectSpiralCorner(
  307. this.currentState.selectStairSet.id,
  308. this.currentState.selectStairSet.index
  309. );
  310. } else {
  311. this.select.endselectSpiralCorner();
  312. this.select.selectSpiralPlane(this.currentState.selectStairSet.id);
  313. }
  314. }
  315. },
  316. // 什么都没选择,在空白区域移动
  317. __selectNotWallSet: function (args) {
  318. if (this.layer.build.tryAddSymbol != null && this.layer.build.tryAddSymbol.attributes.draw) {
  319. var moving = this.layer.move.moveVirtualSymbol2(this.layer.build.tryAddSymbol, args.point);
  320. if (!moving) {
  321. return;
  322. }
  323. } else {
  324. this.select.clearSelect();
  325. }
  326. },
  327. // 移动到墙面上
  328. __selectWallSet: function (args) {
  329. var repeat = !!this.currentState.isRetain(this.previousState);
  330. var r = this.layer.parameter.wallThickness &&
  331. this.layer.parameter.wallThickness / 2;
  332. if (!repeat) {
  333. this.select.clearSelect();
  334. this.currentState.currentendlinePointIndex = this.currentState.selectWallSet.endindex;
  335. this.currentState.currentWallId = this.currentState.selectWallSet.id;
  336. this.currentState.currentstartlinePointIndex = this.currentState.selectWallSet.index;
  337. }
  338. if (this.currentState.addSymbol != null) {
  339. return (
  340. this.layer.build.tryAddSymbol != null &&
  341. this.layer.build.tryAddSymbol.geometry.symbolType != "Stair"
  342. ) && this.layer.move.moveVirtualSymbol1(this.layer.build.tryAddSymbol, args.point) //添加假的元素:门、窗等
  343. }
  344. // 选择的是墙角 角度
  345. if (this.currentState.selectWallSet.type == 0) {
  346. !repeat && this.select.selectWallCorner(
  347. this.currentState.selectWallSet.id,
  348. this.currentState.selectWallSet.index
  349. );
  350. } else if (this.currentState.selectWallSet.type == 1) { //选择墙面
  351. !repeat && (this.select.f_selectWallLine = true);
  352. strategy.__stateChangeWall(args, this.currentState.currentWallId)
  353. }
  354. if (this.select.f_selectWallLine && this.currentState.currentLineId == null) {
  355. this.select.selectStairWallLine(
  356. this.currentState.currentWallId,
  357. this.currentState.currentstartlinePointIndex,
  358. this.currentState.currentendlinePointIndex
  359. );
  360. } else if (!this.select.f_selectWallLine) {
  361. this.select.endSelectWallLine();
  362. }
  363. },
  364. //状态变化,选择墙面
  365. __stateChangeWall: function(args, id) {
  366. //从当前选择的symbol到不选择这个symbol
  367. if (this.currentState.currentSymbolId != null) {
  368. var symbol2d = this.layer.vectors[id].symbol2Ds[this.currentState.currentSymbolId];
  369. var index = Math.min(
  370. symbol2d.attributes.wallstartindex,
  371. symbol2d.attributes.wallendindex
  372. );
  373. var r = this.layer.vectors[id].geometry.wallInfo[index].thick / 2;
  374. if (!this.calculateElement.lineContain(
  375. symbol2d.geometry.point1,
  376. symbol2d.geometry.point2,
  377. args.point, r)
  378. ) {
  379. this.select.endSelectSymbol(
  380. this.select.selectSymbolIds.vectorid,
  381. this.select.selectSymbolIds.selects,
  382. this.select.selectSymbolIds.vectorMeasureid
  383. );
  384. this.select.f_selectSymbol = false;
  385. this.select.f_selectWallLine = true;
  386. }
  387. } else { //当前没有选择symbol
  388. var symbol2d = this.calculateElement.symbolsContain(args.point);
  389. if (symbol2d != null) {
  390. // if
  391. this.select.f_selectWallLine = false;
  392. this.select.drawMeasure(symbol2d);
  393. this.select.selectSymbol(symbol2d);
  394. //选择好symbol的时候,不选择墙面
  395. this.select.f_selectWallLine = false;
  396. }
  397. }
  398. }
  399. }
  400. return function (e) {
  401. for (var key in strategy) {
  402. strategy[key] = strategy[key].bind(this)
  403. }
  404. if (this.layer.control.draggingDialog) {
  405. return
  406. }
  407. var offsetX = (e.offsetX || e.layerX)
  408. var offsetY = (e.offsetY || e.layerY)
  409. var args = {
  410. dx: offsetX - this.lastX, //计算改变的像素值
  411. dy: offsetY - this.lastY,
  412. point: this.layer.getPositionFromPx({ x: offsetX, y: offsetY }), //当前位置
  413. wallid: this.currentState.currentWallId
  414. }
  415. if (args.dx == 0 && args.dy == 0) {
  416. return CanvasSketch.stopEventBubble(e);
  417. }
  418. // 保存最后一次位置
  419. this.lastPoint = this.layer.getPositionFromPx(
  420. { x: this.lastX, y: this.lastY }
  421. );
  422. // 更新位置
  423. this.lastX = offsetX;
  424. this.lastY = offsetY;
  425. for (var i = 0, keys = Object.keys(strategy); i < keys.length; i++) {
  426. if (this[keys[i]]) {
  427. strategy[keys[i]](args);
  428. break;
  429. }
  430. }
  431. (i === keys.length) && strategy.__default(args)
  432. if (this.layer.control.refreshCanvas ||
  433. this.layer.control.refreshBackgroundCanvas ||
  434. this.layer.control.refreshSelectCanvas) {
  435. this.layer.renderer.autoRedraw();
  436. }
  437. CanvasSketch.stopEventBubble(e);
  438. };
  439. }();
  440. Pan.prototype.endPan = function (e) {
  441. if (this.layer.control.draggingDialog) {
  442. return;
  443. }
  444. this.layer.div.style.cursor = "default";
  445. //调整墙的测量线
  446. var flag = false;
  447. if (this.f_draggingWallCorner) {
  448. this.layer.build.adjustEndPoint(this.currentState.currentWallId);
  449. flag = true;
  450. }
  451. else if (this.f_draggingWallLine) {
  452. if (this.dragging.count < 3) {
  453. //弹出编辑框
  454. clearTimeout(this.editwall);
  455. this.editwall = setTimeout("this.layer.menu.showWallDialog()", 800);
  456. this.layer.menu.initEdit2D(this.dragging.wallid, this.dragging.index);
  457. }
  458. else {
  459. this.layer.build.adjustEndPoint(this.currentState.currentWallId);
  460. flag = true;
  461. }
  462. this.dragging.count = 0;
  463. this.f_draggingWallLine = false;
  464. }
  465. else if (this.ajustEndPointForWall != null) {
  466. var ids = this.ajustEndPointForWall.split(";")
  467. this.layer.build.adjustEndPoint2(ids[1], ids[0]);
  468. this.ajustEndPointForWall = null;
  469. flag = true;
  470. }
  471. if (flag) {
  472. this.layer.control.refreshCanvas = true;
  473. this.layer.renderer.autoRedraw();
  474. //调整墙的测量线
  475. }
  476. this.reset();
  477. CanvasSketch.stopEventBubble(e);
  478. };
  479. Pan.prototype.doubleclick = function (e) {
  480. //clearTimeout(this.timeId);
  481. var id = this.currentState.currentWallId;
  482. clearTimeout(this.editwall);
  483. document.getElementById('configuratorWindow2').style.display = "none";
  484. if (this.currentState.currentSymbolId != null) {
  485. return;
  486. }
  487. //建墙
  488. //if(this.currentState.currentLineId==null)
  489. if (this.currentState.startbuild == "wall" || this.currentState.startbuild == "partition") {
  490. this.build.finishWall();
  491. this.layer.control.refreshCanvas = true;
  492. }
  493. else if (this.currentState.startbuild == "WinderStair") {
  494. this.build.buildwallState = null;
  495. this.f_buildingWinderStair = false;
  496. var point = this.layer.getPositionFromPx({ x: (e.offsetX || e.layerX), y: (e.offsetY || e.layerY) });
  497. this.build.BuildingWinderStair(point);
  498. }
  499. //墙面上双击
  500. else if (!this.currentState.startbuild && this.currentState.selectWallSet != null && this.currentState.selectWallSet.type == 1) {
  501. var point = this.layer.getPositionFromPx({ x: (e.offsetX || e.layerX), y: (e.offsetY || e.layerY) });
  502. var line = this.calculateLine.createLine(this.layer.vectors[id].geometry.points[this.currentState.currentstartlinePointIndex], this.layer.vectors[id].geometry.points[this.currentState.currentendlinePointIndex]);
  503. point = this.calculateLine.getJoinLinePoint(point, line);
  504. point = new Point(point.x, point.y);
  505. point.floor = this.layer.vectors[id].geometry.points[this.currentState.currentstartlinePointIndex].floor;
  506. var points = this.layer.vectors[id].geometry.points;
  507. points.splice(this.currentState.currentstartlinePointIndex + 1, 0, point);
  508. var wallInfo = {};
  509. wallInfo.height = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  510. wallInfo.thick = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].thick;
  511. wallInfo.measuredistance = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].measuredistance;
  512. this.layer.vectors[id].geometry.wallInfo.splice(this.currentState.currentstartlinePointIndex + 1, 0, wallInfo);
  513. this.calculateElement.updateSymbolsWallCornerIndexAdd(id, this.currentState.currentstartlinePointIndex + 1, point);
  514. this.layer.vectors[id].geometry.points = points;
  515. this.layer.drawVector(this.layer.vectors[id]);
  516. var index = this.currentState.currentstartlinePointIndex + 1;
  517. //this.layer.vectors[id].geometry.wallInfo[index].height = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  518. //this.layer.vectors[id].geometry.wallInfo[index].thick = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  519. //this.layer.vectors[id].geometry.wallInfo[index].measuredistance = this.layer.vectors[id].geometry.wallInfo[this.currentState.currentstartlinePointIndex].height;
  520. this.select.clearSelect();
  521. this.currentState.currentWallId = id;
  522. this.select.selectWallCorner(id, index);
  523. }
  524. this.layer.renderer.autoRedraw();
  525. CanvasSketch.stopEventBubble(e);
  526. };
  527. Pan.prototype.Events = [["mousedown", Pan.prototype.startPan],
  528. ["mousemove", Pan.prototype.pan],
  529. ["mouseup", Pan.prototype.endPan],
  530. ["dblclick", Pan.prototype.doubleclick]];
  531. Pan.prototype.active = function () {
  532. this.div.addEventListener("mousedown", Pan.prototype.startPan.bind(this), true);
  533. this.div.addEventListener("mousemove", Pan.prototype.pan.bind(this), true);
  534. this.div.addEventListener("mouseup", Pan.prototype.endPan.bind(this), true);
  535. var doubleclick = Pan.prototype.doubleclick.bind(this)
  536. var startTime = null
  537. this.div.addEventListener("click", function() {
  538. if (startTime && Date.now() - startTime <= 300) {
  539. doubleclick.apply(this, arguments)
  540. } else {
  541. startTime = Date.now()
  542. }
  543. }, true);
  544. };
  545. Pan.prototype.reset = function () {
  546. this.f_draggingBackGround = false;
  547. this.f_draggingWallLine = false;
  548. this.f_draggingWallCorner = false;
  549. this.f_draggingStairLine = false;
  550. this.f_draggingStairCorner = false;
  551. this.f_draggingSpiralPlane = false;
  552. this.f_draggingSpiralCorner = false;
  553. this.f_draggingSymbol = false;
  554. this.f_draggingEndpoint = false;
  555. //this.f_buildingWall=false;
  556. this.f_buildingSymbol = false;
  557. };
  558. //新建一个空白页
  559. Pan.prototype.addNew = function () {
  560. document.getElementById("toolbarMenu").addEventListener("click", function (e) {
  561. if (e.target.parentElement.parentElement.id == "toolbarNew") {
  562. if (confirm("您确定要重新打开网页?")) {
  563. //如果是true ,那么就把页面刷新
  564. //location.reload();
  565. this.layer.menu.show2D();
  566. for (var vectorId in this.layer.vectors) {
  567. this.layer.deleteVector(vectorId);
  568. this.layer.data2d.wallIds = [];
  569. }
  570. this.layer.clear();
  571. this.select.clearSelect();
  572. if (my3DEngine != null && typeof (my3DEngine) != "undefined") {
  573. my3DEngine.clearAllSymbols();
  574. my3DEngine = null;
  575. }
  576. one3d = true;
  577. this.currentState.currentWallId = null;
  578. addWall();
  579. }
  580. }
  581. else if (e.target.parentElement.parentElement.id == "toolbarSave") {
  582. alert("save");
  583. }
  584. else if (e.target.parentElement.parentElement.id == "toolbarOption") {
  585. var aw = document.getElementById("aboutWindow");
  586. aw.style.display = "block";
  587. //alert("option");
  588. }
  589. else if (e.target.parentElement.parentElement.id == "userOption") {
  590. alert("user");
  591. }
  592. }.bind(this));
  593. function addWall() {
  594. var vectors = [];
  595. var points = [];
  596. var point1 = new Point(wallleftX, wallleftY);
  597. points.push(point1);
  598. var point2 = new Point(wallrightX, wallleftY);
  599. points.push(point2);
  600. var point3 = new Point(wallrightX, wallrightY);
  601. points.push(point3);
  602. var point4 = new Point(wallleftX, wallrightY);
  603. points.push(point4);
  604. var wall = new Wall(points, document.getElementById("imgWall"));
  605. var vector = new Vector(wall, wallStyle);
  606. wallId = vector.id;
  607. vectors.push(vector);
  608. this.layer.addVectors(vectors);
  609. this.layer.data2d.wallIds.push(wallId);
  610. }
  611. };