Layer.js 33 KB

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