History.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. import { floorplanService } from '../Service/FloorplanService'
  2. import { elementService } from '../Service/ElementService'
  3. import { wallService } from '../Service/WallService'
  4. import { historyUtil } from './HistoryUtil'
  5. import { change } from './Change'
  6. import { stateService } from '../Service/StateService'
  7. import HistoryEvents from '../enum/HistoryEvents'
  8. import { historyService } from '../Service/HistoryService'
  9. import { tagService } from '../Service/TagService'
  10. import { coordinate } from '../Coordinate'
  11. import { signService } from '../Service/SignService'
  12. import { tableService } from '../Service/TableService'
  13. import { rectangleService } from '../Service/RectangleService'
  14. import { circleService } from '../Service/CircleService'
  15. import { arrowService } from '../Service/ArrowService'
  16. import { iconService } from '../Service/IconService'
  17. import { customImageService } from "../Service/CustomImageService";
  18. import mitt from 'mitt'
  19. import { bgImageService } from '../Service/BgImageService'
  20. export default class History {
  21. constructor() {
  22. this.bus = mitt()
  23. }
  24. init() {
  25. change.saveCurrentInfo()
  26. this.bus.emit('redoAvailable', false)
  27. this.bus.emit('undoAvailable', false)
  28. }
  29. clear(){
  30. change.lastData = {};
  31. change.elements = {};
  32. historyService.clearHistoryRecord();
  33. }
  34. save() {
  35. const flag = change.operate()
  36. if (!flag) {
  37. return
  38. }
  39. historyService.addHistoryRecord(change.elements)
  40. change.saveCurrentInfo()
  41. this.setState()
  42. const historyState = historyService.getHistoryState()
  43. if (historyState.pre) {
  44. this.bus.emit('undoAvailable', true)
  45. }
  46. return change.elements
  47. }
  48. setState() {
  49. const state = {
  50. pre: 0,
  51. next: 0,
  52. }
  53. const currentRecordIndex = historyService.getCurrentRecordIndex()
  54. const records = historyService.getHistoryRecords()
  55. if (currentRecordIndex > -1) {
  56. state.pre = 1
  57. }
  58. if (currentRecordIndex < records.length - 1) {
  59. state.next = 1
  60. }
  61. const lastState = historyService.getHistoryState()
  62. if (lastState.pre != state.pre || lastState.next != state.next) {
  63. historyService.setHistoryState(state.pre, state.next)
  64. }
  65. }
  66. // 是否可以撤销
  67. canUndo() {
  68. const state = this.setState()
  69. if (state.pre == 0) {
  70. return false
  71. } else {
  72. return true
  73. }
  74. }
  75. // 是否可以恢复
  76. canRedo() {
  77. const state = this.setState()
  78. if (state.next == 0) {
  79. return false
  80. } else {
  81. return true
  82. }
  83. }
  84. // 撤销
  85. async handleUndo() {
  86. await this.goPreState()
  87. this.layer.renderer.autoRedraw()
  88. const historyState = historyService.getHistoryState()
  89. if (historyState.pre) {
  90. //可以继续撤销
  91. this.bus.emit('undoAvailable', true)
  92. }
  93. else{
  94. //不能继续撤销
  95. this.bus.emit('undoAvailable', false)
  96. }
  97. this.bus.emit('redoAvailable', true)
  98. this.layer.uiControl.clearUI();
  99. }
  100. // 恢复
  101. async handleRedo() {
  102. await this.goNextState()
  103. this.layer.renderer.autoRedraw()
  104. const historyState = historyService.getHistoryState()
  105. if (historyState.next) {
  106. //可以继续恢复
  107. this.bus.emit('redoAvailable', true)
  108. }
  109. else{
  110. //不能继续恢复
  111. this.bus.emit('redoAvailable', false)
  112. }
  113. this.bus.emit('undoAvailable', true)
  114. this.layer.uiControl.clearUI();
  115. }
  116. // 撤销
  117. async goPreState() {
  118. const item = historyService.getHistoryRecord()
  119. if (item) {
  120. stateService.clearItems()
  121. this.layer.uiControl.clearUI()
  122. item.type = 'pre'
  123. this.goPreForPoints(item.points)
  124. this.goPreForWalls(item.walls)
  125. this.goPreForTags(item.tags)
  126. this.goPreForCells(item.cells)
  127. this.goPreForTables(item.tables)
  128. this.goPreForRectangles(item.rectangles)
  129. this.goPreForCircles(item.circles)
  130. this.goPreForArrows(item.arrows)
  131. this.goPreForIcons(item.icons)
  132. this.goPreForSigns(item.signs)
  133. this.goPreForTitle(item.title)
  134. await this.goPreForBgImage (item.bgImage)
  135. this.goPreForCompass(item.compass)
  136. await this.goPreForCustomImages(item.customImages)
  137. historyService.undoHistoryRecord()
  138. change.saveCurrentInfo()
  139. this.setState()
  140. // const points = floorplanService.getPoints()
  141. // if (Object.keys(points).length > 0) {
  142. // this.layer.$xui.toolbar.clear = true
  143. // this.layer.$xui.toolbar.download = true
  144. // } else {
  145. // this.layer.$xui.toolbar.clear = false
  146. // this.layer.$xui.toolbar.download = false
  147. // }
  148. } else {
  149. console.error('goPreState超出范围!')
  150. }
  151. }
  152. goPreForPoints(itemForPoints) {
  153. for (let i = 0; i < itemForPoints.length; ++i) {
  154. const item = itemForPoints[i]
  155. if (item.handle == HistoryEvents.AddPoint) {
  156. historyUtil.deletePoint(item.point.id)
  157. } else if (item.handle == HistoryEvents.DeletePoint) {
  158. let point = wallService.createPoint(item.point.x, item.point.y, item.point.id)
  159. point.parent = JSON.parse(JSON.stringify(item.point.parent))
  160. } else if (item.handle == HistoryEvents.ModifyPoint) {
  161. const prePoint = item.prePoint
  162. let currentPoint = floorplanService.getPoint(item.curPoint.id)
  163. historyUtil.assignPointFromPoint(currentPoint, prePoint)
  164. }
  165. }
  166. }
  167. goPreForWalls(itemForWalls) {
  168. for (let i = 0; i < itemForWalls.length; ++i) {
  169. const item = itemForWalls[i]
  170. if (item.handle == HistoryEvents.AddWall) {
  171. floorplanService.deleteWall(item.wall.id)
  172. } else if (item.handle == HistoryEvents.DeleteWall) {
  173. const preWall = item.wall
  174. let newWall = wallService.createWall(preWall.start, preWall.end, preWall.id)
  175. historyUtil.assignWallFromWall(newWall, preWall)
  176. } else if (item.handle == HistoryEvents.ModifyWall) {
  177. const preWall = item.preWall
  178. let currentWall = floorplanService.getWall(item.curWall.id)
  179. historyUtil.assignWallFromWall(currentWall, preWall)
  180. }
  181. }
  182. }
  183. goPreForSigns(itemForSigns) {
  184. for (let i = 0; i < itemForSigns.length; ++i) {
  185. const item = itemForSigns[i]
  186. if (item.handle == HistoryEvents.AddSign) {
  187. floorplanService.deleteSign(item.sign.id)
  188. } else if (item.handle == HistoryEvents.DeleteSign) {
  189. let vSign = signService.createSign(item.sign.center, item.sign.type, item.sign.id)
  190. historyUtil.assignSignFromSign(vSign, item.sign)
  191. } else if (item.handle == HistoryEvents.ModifySign) {
  192. const preSign = item.preSign
  193. let currentSign = floorplanService.getSign(item.curSign.id)
  194. historyUtil.assignSignFromSign(currentSign, preSign)
  195. }
  196. }
  197. }
  198. goPreForTags(itemForTags) {
  199. for (let i = 0; i < itemForTags.length; ++i) {
  200. const item = itemForTags[i]
  201. if (item.handle == HistoryEvents.AddTag) {
  202. tagService.deleteTag(item.tag.id)
  203. } else if (item.handle == HistoryEvents.DeleteTag) {
  204. let newTag = tagService.createTag(item.tag.center, item.tag.id)
  205. historyUtil.assignTagFromTag(newTag, item.tag)
  206. } else if (item.handle == HistoryEvents.ModifyTag) {
  207. const preTag = item.preTag
  208. let currentTag = floorplanService.getTag(item.curTag.id)
  209. historyUtil.assignTagFromTag(currentTag, preTag)
  210. }
  211. }
  212. }
  213. goPreForCells(itemForCells) {
  214. for (let i = 0; i < itemForCells.length; ++i) {
  215. const item = itemForCells[i]
  216. if (item.handle == HistoryEvents.AddCell) {
  217. tableService.deleteCell(item.cell.id)
  218. } else if (item.handle == HistoryEvents.DeleteCell) {
  219. let newCell = tableService.createCell(item.cell.parent,item.cell.id)
  220. historyUtil.assignCellFromCell(newCell, item.cell)
  221. } else if (item.handle == HistoryEvents.ModifyCell) {
  222. const preCell = item.preCell
  223. let curCell = floorplanService.getCell(item.curCell.id)
  224. historyUtil.assignCellFromCell(curCell, preCell)
  225. }
  226. }
  227. }
  228. goPreForTables(itemForTables) {
  229. for (let i = 0; i < itemForTables.length; ++i) {
  230. const item = itemForTables[i]
  231. if (item.handle == HistoryEvents.AddTable) {
  232. tableService.deleteTable(item.table.id)
  233. } else if (item.handle == HistoryEvents.DeleteTable) {
  234. let newTable = tableService.createTable(item.table.center, item.table.id)
  235. historyUtil.assignTableFromTable(newTable, item.table)
  236. } else if (item.handle == HistoryEvents.ModifyTable) {
  237. const preTable = item.preTable
  238. let curTable = floorplanService.getTable(item.curTable.id)
  239. historyUtil.assignTableFromTable(curTable, preTable)
  240. }
  241. }
  242. }
  243. goPreForRectangles(itemForRectangles) {
  244. for (let i = 0; i < itemForRectangles.length; ++i) {
  245. const item = itemForRectangles[i]
  246. if (item.handle == HistoryEvents.AddRectangle) {
  247. rectangleService.deleteRectangle(item.rectangle.id)
  248. } else if (item.handle == HistoryEvents.DeleteRectangle) {
  249. let newRectangle = rectangleService.createRectangle(item.rectangle.points[0],item.rectangle.points[2],item.rectangle.id)
  250. historyUtil.assignRectangleFromRectangle(newRectangle, item.rectangle)
  251. } else if (item.handle == HistoryEvents.ModifyRectangle) {
  252. const preRectangle = item.preRectangle
  253. let curRectangle = floorplanService.getRectangle(item.curRectangle.id)
  254. historyUtil.assignRectangleFromRectangle(curRectangle, preRectangle)
  255. }
  256. }
  257. }
  258. goPreForCircles(itemForCircles) {
  259. for (let i = 0; i < itemForCircles.length; ++i) {
  260. const item = itemForCircles[i]
  261. if (item.handle == HistoryEvents.AddCircle) {
  262. circleService.deleteCircle(item.circle.id)
  263. } else if (item.handle == HistoryEvents.DeleteCircle) {
  264. let newCircle = circleService.createCircle(item.circle.points[0],item.circle.points[2],item.circle.id)
  265. historyUtil.assignCircleFromCircle(newCircle, item.circle)
  266. } else if (item.handle == HistoryEvents.ModifyCircle) {
  267. const preCircle = item.preCircle
  268. let curCircle = floorplanService.getCircle(item.curCircle.id)
  269. historyUtil.assignCircleFromCircle(curCircle, preCircle)
  270. }
  271. }
  272. }
  273. goPreForArrows(itemForArrows) {
  274. for (let i = 0; i < itemForArrows.length; ++i) {
  275. const item = itemForArrows[i]
  276. if (item.handle == HistoryEvents.AddArrow) {
  277. arrowService.deleteArrow(item.arrow.id)
  278. } else if (item.handle == HistoryEvents.DeleteArrow) {
  279. let newArrow = arrowService.createArrow(item.arrow.startPoint,item.arrow.endPoint,item.arrow.id)
  280. historyUtil.assignArrowFromArrow(newArrow, item.arrow)
  281. } else if (item.handle == HistoryEvents.ModifyArrow) {
  282. const preArrow = item.preArrow
  283. let curArrow = floorplanService.getArrow(item.curArrow.id)
  284. historyUtil.assignArrowFromArrow(curArrow, preArrow)
  285. }
  286. }
  287. }
  288. goPreForIcons(itemForIcons) {
  289. for (let i = 0; i < itemForIcons.length; ++i) {
  290. const item = itemForIcons[i]
  291. if (item.handle == HistoryEvents.AddIcon) {
  292. iconService.deleteIcon(item.icon.id)
  293. } else if (item.handle == HistoryEvents.DeleteIcon) {
  294. let newIcon = iconService.createIcon(item.icon.points[0],item.icon.points[2],item.icon.value,item.icon.id)
  295. historyUtil.assignIconFromIcon(newIcon, item.icon)
  296. } else if (item.handle == HistoryEvents.ModifyIcon) {
  297. const preIcon = item.preIcon
  298. let curIcon = floorplanService.getIcon(item.curIcon.id)
  299. historyUtil.assignIconFromIcon(curIcon, preIcon)
  300. }
  301. }
  302. }
  303. goPreForTitle(itemForTitle) {
  304. if (itemForTitle != null && itemForTitle.handle == HistoryEvents.ModifyTitle) {
  305. const preTitle = itemForTitle.preTitle
  306. let curTitle = floorplanService.getTitle()
  307. historyUtil.assignTitleFromTitle(curTitle, preTitle)
  308. }
  309. }
  310. async goPreForBgImage(itemForBgImage) {
  311. if(itemForBgImage){
  312. if (itemForBgImage.handle == HistoryEvents.AddBgImage) {
  313. bgImageService.deleteBgImage()
  314. } else if (itemForBgImage.handle == HistoryEvents.DeleteBgImage) {
  315. let newBgImage = await bgImageService.createBgImage(itemForBgImage.bgImage.url,itemForBgImage.bgImage.id)
  316. historyUtil.assignBgImageFromBgImage(newBgImage, itemForBgImage.bgImage)
  317. } else if (itemForBgImage.handle == HistoryEvents.ModifyBgImage) {
  318. const preBgImage = itemForBgImage.preBgImage
  319. let curBgImage = floorplanService.getBgImage(itemForBgImage.curBgImage.id)
  320. historyUtil.assignBgImageFromBgImage(curBgImage, preBgImage)
  321. }
  322. }
  323. }
  324. goPreForCompass(itemForCompass) {
  325. if (itemForCompass != null && itemForCompass.handle == HistoryEvents.ModifyCompass) {
  326. const preCompass = itemForCompass.preCompass
  327. let curCompass = floorplanService.getCompass()
  328. historyUtil.assignCompassFromCompass(curCompass, preCompass)
  329. }
  330. }
  331. async goPreForCustomImages(itemForCustomImages) {
  332. for (let i = 0; i < itemForCustomImages.length; ++i) {
  333. const item = itemForCustomImages[i]
  334. if (item.handle == HistoryEvents.AddCustomImage) {
  335. customImageService.deleteCustomImage(item.customImage.id)
  336. } else if (item.handle == HistoryEvents.DeleteCustomImage) {
  337. let newCustomImage = await customImageService.createCustomImage(item.customImage.url,item.customImage.center,item.customImage.id)
  338. historyUtil.assignCustomImageFromCustomImage(newCustomImage, item.customImage)
  339. } else if (item.handle == HistoryEvents.ModifyCustomImage) {
  340. const preCustomImage = item.preCustomImage
  341. let curCustomImage = floorplanService.getCustomImage(item.curCustomImage.id)
  342. historyUtil.assignCustomImageFromCustomImage(curCustomImage, preCustomImage)
  343. }
  344. }
  345. }
  346. goNextForPoints(itemForPoints) {
  347. for (let i = 0; i < itemForPoints.length; ++i) {
  348. const item = itemForPoints[i]
  349. if (item.handle == HistoryEvents.AddPoint) {
  350. let newPoint = wallService.createPoint(item.point.x, item.point.y, item.point.id)
  351. historyUtil.assignPointFromPoint(newPoint, item.point)
  352. } else if (item.handle == HistoryEvents.DeletePoint) {
  353. historyUtil.deletePoint(item.point.id)
  354. } else if (item.handle == HistoryEvents.ModifyPoint) {
  355. const currentPoint = item.curPoint
  356. let prePoint = floorplanService.getPoint(item.curPoint.id)
  357. historyUtil.assignPointFromPoint(prePoint, currentPoint)
  358. }
  359. }
  360. }
  361. goNextForWalls(itemForWalls) {
  362. for (let i = 0; i < itemForWalls.length; ++i) {
  363. const item = itemForWalls[i]
  364. if (item.handle == HistoryEvents.AddWall) {
  365. const preWall = item.wall
  366. let newWall = wallService.createWall(preWall.start, preWall.end, preWall.id)
  367. historyUtil.assignWallFromWall(newWall, preWall)
  368. } else if (item.handle == HistoryEvents.DeleteWall) {
  369. floorplanService.deleteWall(item.wall.id)
  370. } else if (item.handle == HistoryEvents.ModifyWall) {
  371. const currentWall = item.curWall
  372. let preWall = floorplanService.getWall(item.preWall.id)
  373. historyUtil.assignWallFromWall(preWall, currentWall)
  374. }
  375. }
  376. }
  377. goNextForTags(itemForTags) {
  378. for (let i = 0; i < itemForTags.length; ++i) {
  379. const item = itemForTags[i]
  380. if (item.handle == HistoryEvents.AddTag) {
  381. let vTag = tagService.createTag(item.tag.center, item.tag.id)
  382. historyUtil.assignTagFromTag(vTag, item.tag)
  383. } else if (item.handle == HistoryEvents.DeleteTag) {
  384. floorplanService.deleteTag(item.tag.id)
  385. } else if (item.handle == HistoryEvents.ModifyTag) {
  386. const currentTag = item.curTag
  387. let preTag = floorplanService.getTag(item.curTag.id)
  388. historyUtil.assignTagFromTag(preTag, currentTag)
  389. }
  390. }
  391. }
  392. goNextForCells(itemForCells) {
  393. for (let i = 0; i < itemForCells.length; ++i) {
  394. const item = itemForCells[i]
  395. if (item.handle == HistoryEvents.AddCell) {
  396. let vCell = tableService.createCell(item.cell.parent, item.cell.id)
  397. historyUtil.assignCellFromCell(vCell, item.cell)
  398. } else if (item.handle == HistoryEvents.DeleteCell) {
  399. tableService.deleteCell(item.cell.id)
  400. } else if (item.handle == HistoryEvents.ModifyCell) {
  401. const curCell = item.curCell
  402. let preCell = floorplanService.getCell(item.curCell.id)
  403. historyUtil.assignCellFromCell(preCell, curCell)
  404. }
  405. }
  406. }
  407. goNextForTables(itemForTables) {
  408. for (let i = 0; i < itemForTables.length; ++i) {
  409. const item = itemForTables[i]
  410. if (item.handle == HistoryEvents.AddTable) {
  411. let vTable = tableService.createTable(item.table.center, item.table.id)
  412. historyUtil.assignTableFromTable(vTable, item.table)
  413. } else if (item.handle == HistoryEvents.DeleteTable) {
  414. tableService.deleteTable(item.table.id)
  415. } else if (item.handle == HistoryEvents.ModifyTable) {
  416. const curTable = item.curTable
  417. let preTable = floorplanService.getTable(item.curTable.id)
  418. historyUtil.assignTableFromTable(preTable, curTable)
  419. }
  420. }
  421. }
  422. goNextForRectangles(itemForRectangles) {
  423. for (let i = 0; i < itemForRectangles.length; ++i) {
  424. const item = itemForRectangles[i]
  425. if (item.handle == HistoryEvents.AddRectangle) {
  426. let vRectangle = rectangleService.createRectangle(item.rectangle.points[0],item.rectangle.points[2],item.rectangle.id)
  427. historyUtil.assignRectangleFromRectangle(vRectangle, item.rectangle)
  428. } else if (item.handle == HistoryEvents.DeleteRectangle) {
  429. rectangleService.deleteRectangle(item.rectangle.id)
  430. } else if (item.handle == HistoryEvents.ModifyRectangle) {
  431. const currentRectangle = item.curRectangle
  432. let preRectangle = floorplanService.getRectangle(item.curRectangle.id)
  433. historyUtil.assignRectangleFromRectangle(preRectangle, currentRectangle)
  434. }
  435. }
  436. }
  437. goNextForCircles(itemForCircles) {
  438. for (let i = 0; i < itemForCircles.length; ++i) {
  439. const item = itemForCircles[i]
  440. if (item.handle == HistoryEvents.AddCircle) {
  441. let vCircle = circleService.createCircle(item.circle.points[0],item.circle.points[2],item.circle.id)
  442. historyUtil.assignCircleFromCircle(vCircle, item.circle)
  443. } else if (item.handle == HistoryEvents.DeleteCircle) {
  444. floorplanService.deleteCircle(item.circle.id)
  445. } else if (item.handle == HistoryEvents.ModifyCircle) {
  446. const currentCircle = item.curCircle
  447. let preCircle = floorplanService.getCircle(item.curCircle.id)
  448. historyUtil.assignCircleFromCircle(preCircle, currentCircle)
  449. }
  450. }
  451. }
  452. goNextForArrows(itemForArrows) {
  453. for (let i = 0; i < itemForArrows.length; ++i) {
  454. const item = itemForArrows[i]
  455. if (item.handle == HistoryEvents.AddArrow) {
  456. let vArrow = arrowService.createArrow(item.arrow.startPoint,item.arrow.endPoint,item.arrow.id)
  457. historyUtil.assignArrowFromArrow(vArrow, item.arrow)
  458. } else if (item.handle == HistoryEvents.DeleteArrow) {
  459. arrowService.deleteArrow(item.arrow.id)
  460. } else if (item.handle == HistoryEvents.ModifyArrow) {
  461. const currentArrow = item.curArrow
  462. let preArrow = floorplanService.getArrow(item.curArrow.id)
  463. historyUtil.assignArrowFromArrow(preArrow, currentArrow)
  464. }
  465. }
  466. }
  467. goNextForIcons(itemForIcons) {
  468. for (let i = 0; i < itemForIcons.length; ++i) {
  469. const item = itemForIcons[i]
  470. if (item.handle == HistoryEvents.AddIcon) {
  471. let vIcon = iconService.createIcon(item.icon.points[0],item.icon.points[2],item.icon.value,item.icon.id)
  472. historyUtil.assignIconFromIcon(vIcon, item.icon)
  473. } else if (item.handle == HistoryEvents.DeleteIcon) {
  474. iconService.deleteIcon(item.icon.id)
  475. } else if (item.handle == HistoryEvents.ModifyIcon) {
  476. const currentIcon = item.curIcon
  477. let preIcon = floorplanService.getIcon(item.curIcon.id)
  478. historyUtil.assignIconFromIcon(preIcon, currentIcon)
  479. }
  480. }
  481. }
  482. goNextForSigns(itemForSigns) {
  483. for (let i = 0; i < itemForSigns.length; ++i) {
  484. const item = itemForSigns[i]
  485. if (item.handle == HistoryEvents.AddSign) {
  486. let vSign = signService.createSign(item.sign.center, item.sign.type, item.sign.id)
  487. historyUtil.assignSignFromSign(vSign, item.sign)
  488. } else if (item.handle == HistoryEvents.DeleteSign) {
  489. floorplanService.deleteSign(item.sign.id)
  490. } else if (item.handle == HistoryEvents.ModifySign) {
  491. const currentSign = item.curSign
  492. let preSign = floorplanService.getSign(item.curSign.id)
  493. historyUtil.assignSignFromSign(preSign, currentSign)
  494. }
  495. }
  496. }
  497. goNextForTitle(itemForTitle) {
  498. if (itemForTitle != null && itemForTitle.handle == HistoryEvents.ModifyTitle) {
  499. const currentTitle = itemForTitle.curTitle
  500. let preTitle = floorplanService.getTitle()
  501. historyUtil.assignTitleFromTitle(preTitle, currentTitle)
  502. }
  503. }
  504. async goNextForBgImage(itemForBgImage) {
  505. if(itemForBgImage){
  506. if (itemForBgImage.handle == HistoryEvents.AddBgImage) {
  507. let vBgImage = await bgImageService.createBgImage(itemForBgImage.bgImage.url,itemForBgImage.bgImage.center, itemForBgImage.bgImage.id)
  508. historyUtil.assignBgImageFromBgImage(vBgImage, itemForBgImage.bgImage)
  509. } else if (itemForBgImage.handle == HistoryEvents.DeleteBgImage) {
  510. floorplanService.deleteBgImage()
  511. } else if (itemForBgImage.handle == HistoryEvents.ModifyBgImage) {
  512. const currentBgImage = itemForBgImage.curBgImage
  513. let preBgImage = floorplanService.getBgImage(itemForBgImage.curBgImage.id)
  514. historyUtil.assignBgImageFromBgImage(preBgImage, currentBgImage)
  515. }
  516. }
  517. }
  518. goNextForCompass(itemForCompass) {
  519. if (itemForCompass != null && itemForCompass.handle == HistoryEvents.ModifyCompass) {
  520. const currentCompass = itemForCompass.curCompass
  521. let preCompass = floorplanService.getCompass()
  522. historyUtil.assignCompassFromCompass(preCompass, currentCompass)
  523. }
  524. }
  525. async goNextForCustomImages(itemForCustomImages) {
  526. for (let i = 0; i < itemForCustomImages.length; ++i) {
  527. const item = itemForCustomImages[i]
  528. if (item.handle == HistoryEvents.AddCustomImage) {
  529. let vCustomImage = await customImageService.createCustomImage(item.customImage.url,item.customImage.center, item.customImage.id)
  530. historyUtil.assignCustomImageFromCustomImage(vCustomImage, item.customImage)
  531. } else if (item.handle == HistoryEvents.DeleteCustomImage) {
  532. floorplanService.deleteCustomImage(item.customImage.id)
  533. } else if (item.handle == HistoryEvents.ModifyCustomImage) {
  534. const currentCustomImage = item.curCustomImage
  535. let preCustomImage = floorplanService.getCustomImage(item.curCustomImage.id)
  536. historyUtil.assignCustomImageFromCustomImage(preCustomImage, currentCustomImage)
  537. }
  538. }
  539. }
  540. // 恢复
  541. async goNextState() {
  542. historyService.redoHistoryRecord()
  543. const item = historyService.getHistoryRecord()
  544. if (item) {
  545. stateService.clearFocusItem()
  546. //this.layer.$xui.hideProps()
  547. this.layer.uiControl.selectUI = null
  548. let flag = false
  549. if (item.rotate == null) {
  550. flag = false
  551. } else {
  552. flag = this.goNextForAngle(item.rotate)
  553. }
  554. if (!flag) {
  555. this.goNextForPoints(item.points)
  556. this.goNextForWalls(item.walls)
  557. this.goNextForTags(item.tags)
  558. this.goNextForCells(item.cells)
  559. this.goNextForTables(item.tables)
  560. this.goNextForRectangles(item.rectangles)
  561. this.goNextForCircles(item.circles)
  562. this.goNextForArrows(item.arrows)
  563. this.goNextForIcons(item.icons)
  564. this.goNextForSigns(item.signs)
  565. this.goNextForTitle(item.title)
  566. await this.goNextForBgImage (item.bgImage)
  567. this.goNextForCompass(item.compass)
  568. await this.goNextForCustomImages(item.customImages)
  569. }
  570. change.saveCurrentInfo()
  571. this.setState()
  572. } else {
  573. historyService.undoHistoryRecord()
  574. console.error('goNextState超出范围!')
  575. }
  576. }
  577. }
  578. const history = new History()
  579. export { history }