Layer.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. import Load from './Load'
  2. import { stateService } from './Service/StateService'
  3. import { elementService } from './Service/ElementService'
  4. import { floorplanService } from './Service/FloorplanService'
  5. import { tagService } from './Service/TagService'
  6. import { historyService } from './Service/HistoryService'
  7. import UIControl from './Controls/UIControl'
  8. import { moveComponent } from './Controls/MoveComponent'
  9. import { moveTag } from './Controls/MoveTag'
  10. import { addWall } from './Controls/AddWall'
  11. import { moveWall } from './Controls/MoveWall'
  12. import { coordinate } from './Coordinate'
  13. import Render from './Renderer/Render'
  14. import { draw } from './Renderer/Draw'
  15. import { listenLayer } from './ListenLayer'
  16. import { floorplanData } from './FloorplanData'
  17. import LayerEvents from './enum/LayerEvents.js'
  18. import UIEvents from './enum/UIEvents.js'
  19. import SelectState from './enum/SelectState.js'
  20. import Constant from './Constant'
  21. import VectorType from './enum/VectorType'
  22. import { mathUtil } from './MathUtil'
  23. import { wallService } from './Service/WallService'
  24. import { componentService } from './Service/ComponentService'
  25. import History from './History/History'
  26. import { compassService } from './Service/CompassService'
  27. import { furnitureService } from './Service/FurnitureService'
  28. export default class Layer {
  29. constructor() {
  30. //super()
  31. this.load = new Load(this)
  32. this.uiControl = new UIControl(this)
  33. this.renderer = new Render(this)
  34. this.history = new History(this)
  35. this.canvas = null;
  36. this.startX = null
  37. this.startY = null
  38. }
  39. //开始
  40. start(canvas,vectorData) {
  41. coordinate.init(canvas)
  42. this.canvas = canvas;
  43. this.load.load(vectorData);
  44. this.bindEvents()
  45. }
  46. bindEvents() {
  47. this.canvas.addEventListener('contextmenu', function (e) {
  48. e.preventDefault()
  49. })
  50. this.canvas.addEventListener('mousedown', this.onMouseDown.bind(this))
  51. this.canvas.addEventListener('mousemove', this.onMouseMove.bind(this))
  52. this.canvas.addEventListener('mouseup', this.onMouseUp.bind(this))
  53. this.canvas.addEventListener('mousewheel', this.onWheel.bind(this))
  54. this.canvas.addEventListener('DOMMouseScroll', this.onWheel.bind(this))
  55. }
  56. onMouseDown(e) {
  57. this.startX = e.offsetX || e.layerX
  58. this.startY = e.offsetY || e.layerY
  59. this.lastX = e.offsetX || e.layerX
  60. this.lastY = e.offsetY || e.layerY
  61. // 右键
  62. if (e.button == 2) {
  63. this.stopAddVector()
  64. this.uiControl.currentUI = null
  65. this.renderer.autoRedraw()
  66. return
  67. }
  68. const eventName = stateService.getEventName()
  69. //点击第一次
  70. if (eventName == LayerEvents.AddWall) {
  71. let flag = this.setNewWallPoint('start', {
  72. x: this.startX,
  73. y: this.startY,
  74. })
  75. if (!flag) {
  76. return
  77. }
  78. }
  79. //点击第二次
  80. else if (eventName == LayerEvents.AddingWall) {
  81. let flag = this.setNewWallPoint('end', {
  82. x: this.startX,
  83. y: this.startY,
  84. })
  85. if (!flag) {
  86. return
  87. }
  88. if (addWall.canAdd) {
  89. addWall.buildWall(this.uiControl.selectUI == UIEvents.OutWall)
  90. this.history.save()
  91. } else {
  92. return
  93. }
  94. } else {
  95. const selectItem = stateService.getSelectItem()
  96. if (eventName == null && selectItem) {
  97. stateService.setDraggingItem(selectItem)
  98. stateService.setFocusItem(selectItem)
  99. this.uiControl.showAttributes()
  100. this.uiControl.currentUI = selectItem.type
  101. } else if (eventName == null) {
  102. this.uiControl.currentUI = null
  103. }
  104. }
  105. this.setEventName('mouseDown')
  106. // 清除上一个状态
  107. // 设置当前事件名称
  108. e.preventDefault()
  109. e.stopPropagation()
  110. }
  111. onMouseMove(e) {
  112. const X = e.offsetX || e.layerX
  113. const Y = e.offsetY || e.layerY
  114. let dx = X - this.lastX
  115. let dy = Y - this.lastY
  116. let position = coordinate.getXYFromScreen({
  117. x: X,
  118. y: Y,
  119. })
  120. const eventName = stateService.getEventName()
  121. // 是否需要重绘
  122. let needAutoRedraw = false
  123. const draggingItem = stateService.getDraggingItem()
  124. switch (eventName) {
  125. case null:
  126. //监控
  127. needAutoRedraw = listenLayer.start(position)
  128. break
  129. case LayerEvents.PanBackGround:
  130. stateService.clearItems()
  131. coordinate.center.x = coordinate.center.x - (dx * Constant.defaultZoom) / coordinate.zoom / coordinate.res
  132. coordinate.center.y = coordinate.center.y + (dy * Constant.defaultZoom) / coordinate.zoom / coordinate.res
  133. this.lastX = X
  134. this.lastY = Y
  135. needAutoRedraw = true
  136. break
  137. case LayerEvents.AddWall:
  138. stateService.clearDraggingItem()
  139. stateService.clearFocusItem()
  140. needAutoRedraw = true
  141. listenLayer.start(position)
  142. if (listenLayer.modifyPoint) {
  143. position = {
  144. x: listenLayer.modifyPoint.x,
  145. y: listenLayer.modifyPoint.y,
  146. }
  147. }
  148. elementService.execute(null, position)
  149. elementService.setStartAddWall(position)
  150. elementService.showStartAddWall()
  151. break
  152. case LayerEvents.AddingWall:
  153. stateService.clearDraggingItem()
  154. stateService.clearFocusItem()
  155. needAutoRedraw = true
  156. listenLayer.start(position)
  157. let startPosition = {
  158. x: addWall.startInfo.position.x,
  159. y: addWall.startInfo.position.y,
  160. }
  161. if (listenLayer.modifyPoint) {
  162. position = {
  163. x: listenLayer.modifyPoint.x,
  164. y: listenLayer.modifyPoint.y,
  165. }
  166. }
  167. elementService.execute(startPosition, position)
  168. elementService.setStartAddWall(position)
  169. if (!elementService.newWall.display) {
  170. elementService.setNewWall(startPosition, position)
  171. elementService.showNewWall() //画墙
  172. } else {
  173. if (!listenLayer.modifyPoint && addWall.startInfo.linkedPointId) {
  174. let newEndPosition = elementService.checkAngle(position, addWall.startInfo.linkedPointId, null)
  175. if (newEndPosition) {
  176. mathUtil.clonePoint(position, newEndPosition)
  177. }
  178. }
  179. elementService.setNewWallEndPosition(position) //改变end位置
  180. }
  181. addWall.canAdd = addWall.canAddWallForEnd(position)
  182. if (!addWall.canAdd) {
  183. elementService.setNewWallState('error')
  184. } else {
  185. if (this.uiControl.selectUI == UIEvents.OutWall) {
  186. elementService.setNewWallState('normal-out')
  187. } else {
  188. elementService.setNewWallState('normal')
  189. }
  190. }
  191. break
  192. case LayerEvents.MoveWall:
  193. dx = (dx * Constant.defaultZoom) / coordinate.zoom
  194. dy = (dy * Constant.defaultZoom) / coordinate.zoom
  195. // 1表示可以继续移动,2表示不能移动(启动距离还不够),3表示wallId被删除了,4表示重新开始移动(需要达到一定距离才能启动),5表示不能移动(不合适)
  196. let moveFlag = moveWall.moveWallPlane(draggingItem.vectorId, dx, dy)
  197. // 启动的时候需要点距离,所以真正移动了才更新lastX和lastY
  198. if (moveFlag == 1) {
  199. this.lastX = X
  200. this.lastY = Y
  201. needAutoRedraw = true
  202. }
  203. // 需要继续保持移动,一般是距离不够启动
  204. else if (moveFlag == 2) {
  205. }
  206. // wallId被删除了
  207. else if (moveFlag == 3) {
  208. this.history.save()
  209. stateService.clearSelectItem()
  210. stateService.clearDraggingItem()
  211. stateService.clearEventName()
  212. listenLayer.clear()
  213. needAutoRedraw = true
  214. }
  215. // wallId有一端被吸附了,这时候需要重新启动
  216. else if (moveFlag == 4) {
  217. this.lastX = X
  218. this.lastY = Y
  219. this.startX = X
  220. this.startY = Y
  221. needAutoRedraw = true
  222. } else if (moveFlag == 5) {
  223. this.lastX = X
  224. this.lastY = Y
  225. }
  226. break
  227. case LayerEvents.MoveWallPoint:
  228. let point = floorplanService.getPoint(draggingItem.vectorId)
  229. listenLayer.start(position, draggingItem.vectorId, point.parent)
  230. if (listenLayer.modifyPoint) {
  231. position = {
  232. x: listenLayer.modifyPoint.x,
  233. y: listenLayer.modifyPoint.y,
  234. }
  235. }
  236. elementService.execute(null, position)
  237. let flag = moveWall.movePoint(draggingItem.vectorId, position, listenLayer.modifyPoint)
  238. if (!flag) {
  239. elementService.hideAll()
  240. }
  241. needAutoRedraw = true
  242. break
  243. case LayerEvents.AddComponent:
  244. needAutoRedraw = true
  245. if (draggingItem == null) {
  246. const componentType = this.uiControl.getComponentTypeForUI()
  247. const component = componentService.createComponent(position, componentType)
  248. if (component.vectorId) {
  249. stateService.setSelectItem(component.vectorId, componentType, SelectState.All)
  250. stateService.setDraggingItem(stateService.selectItem)
  251. }
  252. } else {
  253. let flag = moveComponent.moveFullComponent(position, draggingItem.vectorId)
  254. if (flag) {
  255. this.lastX = X
  256. this.lastY = Y
  257. this.startX = X
  258. this.startY = Y
  259. }
  260. }
  261. break
  262. case LayerEvents.MoveComponent:
  263. needAutoRedraw = true
  264. if (draggingItem != null && componentService.isComponent(draggingItem.type)) {
  265. let flag = moveComponent.moveFullComponent(position, draggingItem.vectorId)
  266. if (flag) {
  267. this.lastX = X
  268. this.lastY = Y
  269. this.startX = X
  270. this.startY = Y
  271. }
  272. }
  273. break
  274. case LayerEvents.AddTag:
  275. needAutoRedraw = true
  276. if (draggingItem == null) {
  277. const tag = tagService.createTag(position)
  278. if (tag.vectorId) {
  279. stateService.setSelectItem(tag.vectorId, VectorType.Tag, SelectState.All)
  280. stateService.setDraggingItem(stateService.selectItem)
  281. }
  282. } else {
  283. moveTag.moveFullTag(position, draggingItem.vectorId)
  284. }
  285. break
  286. case LayerEvents.MoveTag:
  287. needAutoRedraw = true
  288. if (draggingItem != null) {
  289. moveTag.moveFullTag(position, draggingItem.vectorId)
  290. }
  291. break
  292. case LayerEvents.AddFurniture:
  293. needAutoRedraw = true
  294. if (draggingItem == null) {
  295. const furnitureType = this.uiControl.getFurnitureTypeForUI()
  296. const furniture = furnitureService.createFurniture(position, furnitureType)
  297. if (furniture.vectorId) {
  298. stateService.setSelectItem(furniture.vectorId, furnitureType, SelectState.All)
  299. stateService.setDraggingItem(stateService.selectItem)
  300. }
  301. } else {
  302. const furniture = floorplanService.getFurniture(draggingItem.vectorId)
  303. mathUtil.clonePoint(furniture.center, position)
  304. }
  305. break
  306. case LayerEvents.MoveFurniture:
  307. needAutoRedraw = true
  308. const furniture = floorplanService.getFurniture(draggingItem.vectorId)
  309. mathUtil.clonePoint(furniture.center, position)
  310. break
  311. }
  312. if (needAutoRedraw) {
  313. this.renderer.autoRedraw()
  314. }
  315. }
  316. onMouseUp(e) {
  317. if (coordinate.defaultCenter == null) {
  318. return
  319. }
  320. const X = e.offsetX || e.layerX
  321. const Y = e.offsetY || e.layerY
  322. let eventName = stateService.getEventName()
  323. const draggingItem = stateService.getDraggingItem()
  324. let focusItem = null
  325. if (draggingItem && draggingItem.vectorId) {
  326. focusItem = {
  327. vectorId: draggingItem.vectorId,
  328. type: draggingItem.type,
  329. cursor: { x: this.lastX, y: this.lastY },
  330. }
  331. stateService.setFocusItem(focusItem)
  332. this.uiControl.showAttributes()
  333. }
  334. let position = coordinate.getXYFromScreen({
  335. x: X,
  336. y: Y,
  337. })
  338. let needAutoRedraw = false
  339. let symbol = null
  340. switch (eventName) {
  341. case null:
  342. return
  343. case LayerEvents.PanBackGround:
  344. needAutoRedraw = true
  345. stateService.clearFocusItem()
  346. this.uiControl.currentUI = null
  347. break
  348. case LayerEvents.MoveWallPoint:
  349. needAutoRedraw = true
  350. elementService.hideAll()
  351. let point = floorplanService.getPoint(draggingItem.vectorId)
  352. if (point) {
  353. //if (focusItem == null) {
  354. listenLayer.start(point, draggingItem.vectorId, point.parent)
  355. if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedPointId')) {
  356. wallService.moveTo(draggingItem.vectorId, listenLayer.modifyPoint.linkedPointId)
  357. } else if (listenLayer.modifyPoint && (listenLayer.modifyPoint.linkedPointIdX || listenLayer.modifyPoint.linkedPointIdY)) {
  358. mathUtil.clonePoint(point, listenLayer.modifyPoint)
  359. } else if (listenLayer.modifyPoint && listenLayer.modifyPoint.hasOwnProperty('linkedWallId')) {
  360. point = wallService.createPoint(listenLayer.modifyPoint.x, listenLayer.modifyPoint.y)
  361. wallService.splitWall(listenLayer.modifyPoint.linkedWallId, point.vectorId, 'start')
  362. wallService.moveTo(draggingItem.vectorId, point.vectorId)
  363. } else if (moveWall.splitWallId != null) {
  364. wallService.splitWall(moveWall.splitWallId, draggingItem.vectorId, 'start')
  365. }
  366. //draggingItem.vectorId所在的墙面与其他墙角相交
  367. moveWall.updateForAbsorbWallPoints()
  368. this.history.save()
  369. }
  370. break
  371. case LayerEvents.AddingWall:
  372. needAutoRedraw = true
  373. if (addWall.startInfo && addWall.startInfo.linkedPointId) {
  374. let addWallStartPoint = floorplanService.getPoint(addWall.startInfo.linkedPointId)
  375. if (addWall.endInfo.position && Object.keys(addWallStartPoint.parent).length > 1) {
  376. stateService.clearEventName()
  377. addWall.clear()
  378. elementService.hideAll()
  379. }
  380. }
  381. break
  382. case LayerEvents.MoveWall:
  383. needAutoRedraw = true
  384. if (focusItem != null && focusItem.type == VectorType.Wall) {
  385. const wall = floorplanService.getWall(focusItem.vectorId)
  386. if (wall.import || wall.out) {
  387. this.uiControl.currentUI = 'OutWall'
  388. } else {
  389. this.uiControl.currentUI = focusItem.type
  390. }
  391. this.history.save()
  392. } else {
  393. this.history.save()
  394. }
  395. break
  396. case LayerEvents.AddSymbol:
  397. if (draggingItem == null) {
  398. this.setEventName('mouseUp')
  399. return
  400. }
  401. focusItem = {
  402. vectorId: draggingItem.vectorId,
  403. type: draggingItem.type,
  404. cursor: { x: this.lastX, y: this.lastY },
  405. }
  406. stateService.setFocusItem(focusItem)
  407. this.uiControl.showAttributes()
  408. this.uiControl.currentUI = focusItem.type
  409. this.history.save()
  410. break
  411. case LayerEvents.AddComponent:
  412. focusItem = {
  413. vectorId: draggingItem.vectorId,
  414. type: draggingItem.type,
  415. cursor: { x: this.lastX, y: this.lastY },
  416. }
  417. stateService.setFocusItem(focusItem)
  418. this.uiControl.showAttributes()
  419. this.uiControl.currentUI = focusItem.type
  420. this.history.save()
  421. break
  422. case LayerEvents.MoveComponent:
  423. needAutoRedraw = true
  424. if (focusItem != null && componentService.isComponent(focusItem.type)) {
  425. this.uiControl.currentUI = focusItem.type
  426. this.history.save()
  427. } else {
  428. this.history.save()
  429. }
  430. break
  431. case LayerEvents.MoveTag:
  432. needAutoRedraw = true
  433. if (focusItem != null && focusItem.type == VectorType.Tag) {
  434. this.uiControl.currentUI = focusItem.type
  435. this.history.save()
  436. } else {
  437. this.history.save()
  438. }
  439. break
  440. case LayerEvents.AddTag:
  441. needAutoRedraw = true
  442. let tag = floorplanService.getTag(draggingItem.vectorId)
  443. tag.setAdding(false)
  444. focusItem = {
  445. vectorId: draggingItem.vectorId,
  446. type: draggingItem.type,
  447. cursor: { x: this.lastX, y: this.lastY },
  448. }
  449. stateService.setFocusItem(focusItem)
  450. this.history.save()
  451. this.uiControl.currentUI = focusItem.type
  452. break
  453. case LayerEvents.AddFurniture:
  454. focusItem = {
  455. vectorId: draggingItem.vectorId,
  456. type: draggingItem.type,
  457. cursor: { x: this.lastX, y: this.lastY },
  458. }
  459. stateService.setFocusItem(focusItem)
  460. this.uiControl.showAttributes()
  461. this.uiControl.currentUI = focusItem.type
  462. this.history.save()
  463. break
  464. case LayerEvents.MoveFurniture:
  465. needAutoRedraw = true
  466. if (focusItem != null && furnitureService.isFurniture(focusItem.type)) {
  467. this.uiControl.currentUI = focusItem.type
  468. this.history.save()
  469. } else {
  470. debugger
  471. this.history.save()
  472. }
  473. break
  474. }
  475. this.setEventName('mouseUp')
  476. stateService.clearDraggingItem()
  477. this.renderer.autoRedraw()
  478. }
  479. onWheel(e) {
  480. if (coordinate.defaultCenter == null) {
  481. return
  482. }
  483. e.preventDefault()
  484. const type = e.type
  485. if (type == 'DOMMouseScroll' || type == 'mousewheel') {
  486. // 当在canvas用滚轮滚动时
  487. const delta = e.wheelDelta ? (e.wheelDelta / 120) * 2 : (-(e.detail || 0) / 3) * 2
  488. const zoom = coordinate.zoom + delta
  489. if (zoom < 14) {
  490. return
  491. }
  492. coordinate.updateZoom(zoom)
  493. let info = coordinate.getScreenInfoForCAD()
  494. info.floorPlanAngle = floorplanService.getAngle()
  495. this.renderer.autoRedraw()
  496. }
  497. }
  498. onKeydown(e) {
  499. if (!this.display) {
  500. return
  501. }
  502. if (e.ctrlKey && e.code == 'KeyZ') {
  503. // 撤销
  504. if (!this.$xui.toolbar.recall) {
  505. return
  506. }
  507. this.revokeHistory()
  508. console.log('ctrl+z')
  509. } else if (e.ctrlKey && e.code == 'KeyY') {
  510. // 恢复
  511. if (!this.$xui.toolbar.recover) {
  512. return
  513. }
  514. this.recoveryHistory()
  515. console.log('ctrl+y')
  516. } else if (e.code == 'Delete') {
  517. this.deleteItem()
  518. this.uiControl.currentUI = null
  519. this.history.save()
  520. this.renderer.autoRedraw()
  521. console.log('Delete')
  522. } else if (e.code == 'Escape') {
  523. this.stopAddVector()
  524. this.renderer.autoRedraw()
  525. console.log('Esc')
  526. }
  527. }
  528. //点击左侧栏后,更新事件
  529. updateEventNameForSelectUI() {
  530. elementService.hideAll()
  531. //正在添加tag的时候,需要先删除
  532. const eventName = stateService.getEventName()
  533. if (eventName == LayerEvents.AddTag) {
  534. let item = stateService.getDraggingItem()
  535. if (item && item.type == VectorType.Tag) {
  536. floorplanService.deleteTag(item.vectorId)
  537. }
  538. }
  539. stateService.clearItems()
  540. if (this.uiControl.selectUI == UIEvents.Wall || this.uiControl.selectUI == UIEvents.OutWall) {
  541. stateService.setEventName(LayerEvents.AddWall)
  542. } else if (
  543. this.uiControl.selectUI == UIEvents.SingleDoor ||
  544. this.uiControl.selectUI == UIEvents.DoubleDoor ||
  545. this.uiControl.selectUI == UIEvents.SlideDoor ||
  546. this.uiControl.selectUI == UIEvents.SingleWindow ||
  547. this.uiControl.selectUI == UIEvents.BayWindow ||
  548. this.uiControl.selectUI == UIEvents.FrenchWindow ||
  549. this.uiControl.selectUI == UIEvents.Pass
  550. ) {
  551. stateService.setEventName(LayerEvents.AddSymbol)
  552. } else if (this.uiControl.selectUI == UIEvents.Beam || this.uiControl.selectUI == UIEvents.Flue || this.uiControl.selectUI == UIEvents.Corridor) {
  553. stateService.setEventName(LayerEvents.AddComponent)
  554. } else if (this.uiControl.selectUI == UIEvents.Tag) {
  555. stateService.setEventName(LayerEvents.AddTag)
  556. } else if (
  557. this.uiControl.selectUI == UIEvents.TV ||
  558. this.uiControl.selectUI == UIEvents.CombinationSofa ||
  559. this.uiControl.selectUI == UIEvents.SingleSofa ||
  560. this.uiControl.selectUI == UIEvents.TeaTable ||
  561. this.uiControl.selectUI == UIEvents.Carpet ||
  562. this.uiControl.selectUI == UIEvents.Plant ||
  563. this.uiControl.selectUI == UIEvents.DiningTable ||
  564. this.uiControl.selectUI == UIEvents.DoubleBed ||
  565. this.uiControl.selectUI == UIEvents.SingleBed ||
  566. this.uiControl.selectUI == UIEvents.Wardrobe ||
  567. this.uiControl.selectUI == UIEvents.Dresser ||
  568. this.uiControl.selectUI == UIEvents.BedsideCupboard ||
  569. this.uiControl.selectUI == UIEvents.Pillow ||
  570. this.uiControl.selectUI == UIEvents.GasStove ||
  571. this.uiControl.selectUI == UIEvents.Cupboard ||
  572. this.uiControl.selectUI == UIEvents.Bathtub ||
  573. this.uiControl.selectUI == UIEvents.Closestool ||
  574. this.uiControl.selectUI == UIEvents.Washstand ||
  575. this.uiControl.selectUI == UIEvents.Desk ||
  576. this.uiControl.selectUI == UIEvents.BalconyChair ||
  577. this.uiControl.selectUI == UIEvents.Elevator
  578. ) {
  579. stateService.setEventName(LayerEvents.AddFurniture)
  580. }
  581. }
  582. setEventName(eventType) {
  583. let eventName = stateService.getEventName()
  584. if (eventType == 'mouseDown') {
  585. if (eventName == null) {
  586. const selectItem = stateService.getSelectItem()
  587. if (selectItem == null) {
  588. stateService.setEventName(LayerEvents.PanBackGround)
  589. } else if (selectItem.type == VectorType.Wall) {
  590. stateService.setEventName(LayerEvents.MoveWall)
  591. } else if (selectItem.type == VectorType.WallCorner) {
  592. stateService.setEventName(LayerEvents.MoveWallPoint)
  593. } else if (componentService.isComponent(selectItem.type)) {
  594. stateService.setEventName(LayerEvents.MoveComponent)
  595. } else if (selectItem.type == VectorType.Tag) {
  596. stateService.setEventName(LayerEvents.MoveTag)
  597. } else if (furnitureService.isFurniture(selectItem.type)) {
  598. stateService.setEventName(LayerEvents.MoveFurniture)
  599. }
  600. } else if (eventName == LayerEvents.AddWall) {
  601. stateService.setEventName(LayerEvents.AddingWall)
  602. }
  603. } else if (eventType == 'mouseUp') {
  604. if (eventName == LayerEvents.AddTag) {
  605. //可连续添加
  606. } else if (eventName != LayerEvents.AddWall && eventName != LayerEvents.AddingWall) {
  607. stateService.clearEventName()
  608. }
  609. }
  610. }
  611. exit() {
  612. stateService.clearItems()
  613. stateService.clearEventName()
  614. this.uiControl.clearUI()
  615. }
  616. stopAddVector() {
  617. let eventName = stateService.getEventName()
  618. if (eventName != LayerEvents.AddingWall) {
  619. stateService.clearEventName()
  620. const draggingItem = stateService.getDraggingItem()
  621. if (eventName == LayerEvents.AddSymbol) {
  622. if (draggingItem && draggingItem.vectorId) {
  623. stateService.clearDraggingItem()
  624. }
  625. } else if (eventName == LayerEvents.AddComponent) {
  626. if (draggingItem && draggingItem.vectorId) {
  627. floorplanService.deleteComponent(draggingItem.vectorId)
  628. }
  629. } else if (eventName == LayerEvents.AddTag) {
  630. if (draggingItem && draggingItem.vectorId) {
  631. tagService.deleteTag(draggingItem.vectorId)
  632. this.uiControl.currentUI = null
  633. }
  634. } else if (eventName == LayerEvents.AddFurniture) {
  635. if (draggingItem && draggingItem.vectorId) {
  636. floorplanService.deleteFurniture(draggingItem.vectorId)
  637. }
  638. }
  639. } else {
  640. stateService.setEventName(LayerEvents.AddWall)
  641. }
  642. this.uiControl.clearUI()
  643. elementService.hideAll()
  644. }
  645. setNewWallPoint(dir, position) {
  646. if (listenLayer.symbolInfo.state == 'select') {
  647. return false
  648. }
  649. if (dir == 'start') {
  650. if (listenLayer.modifyPoint) {
  651. addWall.setPointInfo(dir, listenLayer.modifyPoint)
  652. } else {
  653. addWall.setPointInfo(dir, coordinate.getXYFromScreen(position))
  654. }
  655. return true
  656. } else if (dir == 'end') {
  657. if (listenLayer.modifyPoint) {
  658. addWall.setPointInfo(dir, listenLayer.modifyPoint)
  659. } else {
  660. addWall.setPointInfo(dir, coordinate.getXYFromScreen(position))
  661. }
  662. return true
  663. }
  664. return false
  665. }
  666. deleteItem() {
  667. let item = stateService.getFocusItem()
  668. if (item) {
  669. if (item.type == VectorType.Wall) {
  670. floorplanService.deleteWall(item.vectorId)
  671. } else if (componentService.isComponent(item.type)) {
  672. floorplanService.deleteComponent(item.vectorId)
  673. } else if (item.type == VectorType.Tag) {
  674. floorplanService.deleteTag(item.vectorId)
  675. } else if (furnitureService.isFurniture(item.type)) {
  676. floorplanService.deleteComponent(item.vectorId)
  677. } else if (item.type == VectorType.WallCorner) {
  678. wallService.deleteWallCorner(item.vectorId)
  679. }
  680. this.history.save()
  681. this.renderer.autoRedraw()
  682. }
  683. }
  684. }