Pan.js 23 KB

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