HistoryUtil.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. import { mathUtil } from '../MathUtil'
  2. import { arrowService } from '../Service/ArrowService'
  3. import { circleService } from '../Service/CircleService'
  4. import { floorplanService } from '../Service/FloorplanService'
  5. import { iconService } from '../Service/IconService'
  6. import { rectangleService } from '../Service/RectangleService'
  7. import { signService } from '../Service/SignService'
  8. import { tableService } from '../Service/TableService'
  9. import { tagService } from '../Service/TagService'
  10. import { wallService } from '../Service/WallService'
  11. export default class HistoryUtil {
  12. constructor() {}
  13. isDifferentForWalls(wall1, wall2) {
  14. if (wall1.start == wall2.start && wall1.end == wall2.end) {
  15. return false
  16. } else {
  17. return true
  18. }
  19. }
  20. isDifferentForTags(tag1, tag2) {
  21. if (mathUtil.equalPoint(tag1.center, tag2.center) && tag1.value == tag2.value) {
  22. return false
  23. } else {
  24. return true
  25. }
  26. }
  27. isDifferentForTables(table1, table2) {
  28. if(!mathUtil.equalPoint(table1.center, table2.center)){
  29. return true;
  30. }
  31. else if(table1.rowLen != table2.rowLen || table1.colLen != table2.colLen || table1.cells.length != table2.cells.length){
  32. return true;
  33. }
  34. else{
  35. for(let i=0;i<table1.cells.length;++i){
  36. for(let j=0;j<table1.cells[i].length;++j){
  37. const cell1 = floorplanService.getCell(table1.cells[i][j]);
  38. const cell2 = floorplanService.getCell(table2.cells[i][j]);
  39. if(this.isDifferentForCells(cell1,cell2)){
  40. return true;
  41. }
  42. }
  43. }
  44. }
  45. return false
  46. }
  47. isDifferentForCells(cell1, cell2) {
  48. if (cell1.value == cell2.value&&cell1.width == cell2.width&&cell1.height == cell2.height) {
  49. return false
  50. } else {
  51. return true
  52. }
  53. }
  54. isDifferentForRectangles(rectangle1, rectangle2) {
  55. for(let i=0;i<rectangle1.points.length;++i){
  56. if(!mathUtil.equalPoint(rectangle1.points[i], rectangle2.points[i])){
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. isDifferentForCircles(circle1, circle2) {
  63. if(!mathUtil.equalPoint(circle1.center, circle2.center)){
  64. return true;
  65. }
  66. else if(circle1.radius != circle2.radius){
  67. return true;
  68. }
  69. else {
  70. for(let i=0;i<circle1.points.length;++i){
  71. if(!mathUtil.equalPoint(circle1.points[i], circle2.points[i])){
  72. return true;
  73. }
  74. }
  75. }
  76. return false;
  77. }
  78. isDifferentForArrows(arrow1, arrow2) {
  79. if (mathUtil.equalPoint(arrow1.startPoint, arrow2.startPoint) && mathUtil.equalPoint(arrow1.endPoint, arrow2.endPoint)) {
  80. return false
  81. } else {
  82. return true
  83. }
  84. }
  85. isDifferentForIcons(icon1, icon2) {
  86. if(!mathUtil.equalPoint(icon1.center, icon2.center)){
  87. return true;
  88. }
  89. else if(icon1.radius != icon2.radius){
  90. return true;
  91. }
  92. else if(icon1.value != icon2.value){
  93. return true;
  94. }
  95. else if(icon1.angle != icon2.angle){
  96. return true;
  97. }
  98. else {
  99. for(let i=0;i<icon1.points.length;++i){
  100. if(!mathUtil.equalPoint(icon1.points[i], icon2.points[i])){
  101. return true;
  102. }
  103. }
  104. }
  105. return false;
  106. }
  107. isDifferentForSigns(sign1, sign2) {
  108. if (sign1.scale == sign2.scale && JSON.stringify(sign1.center) == JSON.stringify(sign2.center) && sign1.angle == sign2.angle) {
  109. return false
  110. } else {
  111. return true
  112. }
  113. }
  114. isDifferentForTitle(title1, title2) {
  115. if (title1.value == title2.value) {
  116. return false
  117. } else {
  118. return true
  119. }
  120. }
  121. isDifferentForImage(image1, image2) {
  122. if (image1.src == image2.src) {
  123. return false
  124. } else {
  125. return true
  126. }
  127. }
  128. isDifferentForCompass(compass1, compass2) {
  129. if (compass1.angle == compass2.angle) {
  130. return false
  131. } else {
  132. return true
  133. }
  134. }
  135. // isDifferentForAngle(angle1, angle2) {
  136. // if (angle1 == angle2) {
  137. // return false
  138. // } else {
  139. // return true
  140. // }
  141. // }
  142. // wall2赋值给wall1
  143. assignWallFromWall(wall1, wall2) {
  144. const wallInfo = {}
  145. wallInfo.vectorId = wall1.vectorId
  146. wallInfo.start = wall2.start
  147. wallInfo.end = wall2.end
  148. wallService.setWallInfo(wallInfo)
  149. }
  150. assignPointFromPoint(point1, point2) {
  151. const pointInfo = {}
  152. pointInfo.vectorId = point1.vectorId
  153. pointInfo.position = { x: point2.x, y: point2.y }
  154. pointInfo.parent = JSON.parse(JSON.stringify(point2.parent))
  155. wallService.setPointInfo(pointInfo)
  156. }
  157. assignTagFromTag(tag1, tag2) {
  158. const tagInfo = {}
  159. tagInfo.vectorId = tag1.vectorId
  160. tagInfo.value = tag2.value
  161. tagInfo.center = JSON.parse(JSON.stringify(tag2.center))
  162. tagInfo.points2d = JSON.parse(JSON.stringify(tag2.points))
  163. tagService.setTagInfo(tagInfo)
  164. }
  165. assignTableFromTable(table1, table2) {
  166. const tableInfo = {}
  167. tableInfo.vectorId = table1.vectorId
  168. tableInfo.rowLen = table2.rowLen
  169. tableInfo.colLen = table2.colLen
  170. tableInfo.center = JSON.parse(JSON.stringify(table2.center))
  171. tableInfo.points = JSON.parse(JSON.stringify(table2.points))
  172. tableInfo.cells = table2.cells
  173. tableService.setTableInfo(tableInfo)
  174. }
  175. assignTagFromTag(tag1, tag2) {
  176. const tagInfo = {}
  177. tagInfo.vectorId = tag1.vectorId
  178. tagInfo.value = tag2.value
  179. tagInfo.center = JSON.parse(JSON.stringify(tag2.center))
  180. tagInfo.points2d = JSON.parse(JSON.stringify(tag2.points))
  181. tagService.setTagInfo(tagInfo)
  182. }
  183. assignRectangleFromRectangle(rectangle1, rectangle2) {
  184. const rectangleInfo = {}
  185. rectangleInfo.vectorId = rectangle1.vectorId
  186. rectangleInfo.angle = rectangle2.angle
  187. rectangleInfo.points = JSON.parse(JSON.stringify(rectangle2.points))
  188. rectangleService.setRectangleInfo(rectangleInfo)
  189. }
  190. assignCircleFromCircle(circle1, circle2) {
  191. const circleInfo = {}
  192. circleInfo.vectorId = circle1.vectorId
  193. circleInfo.radius = circle2.radius
  194. circleInfo.center = JSON.parse(JSON.stringify(circle2.center))
  195. circleInfo.points = JSON.parse(JSON.stringify(circle2.points))
  196. circleService.setCircleInfo(circleInfo)
  197. }
  198. assignArrowFromArrow(arrow1, arrow2) {
  199. const arrowInfo = {}
  200. arrowInfo.vectorId = arrow1.vectorId
  201. arrowInfo.startPoint = JSON.parse(JSON.stringify(arrow2.startPoint))
  202. arrowInfo.endPoint = JSON.parse(JSON.stringify(arrow2.endPoint))
  203. arrowService.setArrowInfo(arrowInfo)
  204. }
  205. assignIconFromIcon(icon1, icon2) {
  206. const iconInfo = {}
  207. iconInfo.vectorId = icon1.vectorId
  208. iconInfo.radius = icon2.radius
  209. iconInfo.value = icon2.value
  210. iconInfo.angle = icon2.angle
  211. iconInfo.center = JSON.parse(JSON.stringify(icon2.center))
  212. iconInfo.points = JSON.parse(JSON.stringify(icon2.points))
  213. iconService.setIconInfo(iconInfo)
  214. }
  215. assignSignFromSign(sign1, sign2) {
  216. const SignInfo = {}
  217. SignInfo.vectorId = sign1.vectorId
  218. SignInfo.angle = sign2.angle
  219. SignInfo.center = JSON.parse(JSON.stringify(sign2.center))
  220. SignInfo.scale = sign2.scale
  221. signService.setSignInfo(SignInfo)
  222. }
  223. assignTitleFromTitle(title1, title2) {
  224. const titleInfo = {}
  225. titleInfo.vectorId = title1.vectorId
  226. titleInfo.value = title2.value
  227. floorplanService.updateTitle(titleInfo.value)
  228. }
  229. assignImageFromImage(image1, image2) {
  230. const imageInfo = {}
  231. imageInfo.vectorId = image1.vectorId
  232. imageInfo.src = image2.src
  233. floorplanService.updateBgImage(imageInfo.src)
  234. }
  235. assignCompassFromCompass(compass1, compass2) {
  236. const compassInfo = {}
  237. compassInfo.vectorId = compass1.vectorId
  238. compassInfo.angle = compass2.angle
  239. floorplanService.updateCompass(compassInfo.angle )
  240. }
  241. deletePoint(pointId) {
  242. const point = floorplanService.getPoint(pointId)
  243. const parent = point.parent
  244. for (const key in parent) {
  245. floorplanService.deletePoint(pointId, key)
  246. }
  247. }
  248. getDataForPoint(point) {
  249. const data = {}
  250. data.id = point.vectorId
  251. mathUtil.clonePoint(data, point)
  252. data.parent = JSON.parse(JSON.stringify(point.parent))
  253. data.type = point.geoType
  254. return data
  255. }
  256. getDataForWall(wall) {
  257. const data = {}
  258. data.id = wall.vectorId
  259. data.start = wall.start
  260. data.end = wall.end
  261. data.type = wall.geoType
  262. return data
  263. }
  264. getDataForSign(sign) {
  265. const data = {}
  266. data.id = sign.vectorId
  267. data.type = sign.geoType
  268. data.center = JSON.parse(JSON.stringify(sign.center))
  269. data.scale = sign.scale
  270. data.angle = sign.angle
  271. return data
  272. }
  273. getDataForTag(tag) {
  274. const data = {}
  275. data.id = tag.vectorId
  276. data.type = tag.geoType
  277. data.center = {}
  278. mathUtil.clonePoint(data.center, tag.center)
  279. data.points = [].concat(tag.points2d)
  280. data.value = tag.value
  281. return data
  282. }
  283. getDataForTable(table) {
  284. const data = {}
  285. data.id = table.vectorId
  286. data.type = table.geoType
  287. data.rowLen = table.rowLen
  288. data.colLen = table.colLen
  289. data.center = {}
  290. mathUtil.clonePoint(data.center, table.center)
  291. data.points = [].concat(table.points)
  292. data.cells = [].concat(table.cells)
  293. return data
  294. }
  295. getDataForRectangle(rectangle) {
  296. const data = {}
  297. data.id = rectangle.vectorId
  298. data.type = rectangle.geoType
  299. data.angle = rectangle.angle
  300. data.points = [].concat(rectangle.points)
  301. return data
  302. }
  303. getDataForCircle(circle) {
  304. const data = {}
  305. data.id = circle.vectorId
  306. data.type = circle.geoType
  307. data.center = {}
  308. mathUtil.clonePoint(data.center, circle.center)
  309. data.points = [].concat(circle.points)
  310. data.radius = circle.radius
  311. return data
  312. }
  313. getDataForArrow(arrow) {
  314. const data = {}
  315. data.id = arrow.vectorId
  316. data.type = arrow.geoType
  317. data.startPoint = {}
  318. mathUtil.clonePoint(data.startPoint, arrow.startPoint)
  319. data.endPoint = {}
  320. mathUtil.clonePoint(data.endPoint, arrow.endPoint)
  321. return data
  322. }
  323. getDataForIcon(icon) {
  324. const data = {}
  325. data.id = icon.vectorId
  326. data.type = icon.geoType
  327. data.value = icon.value
  328. data.angle = icon.angle
  329. data.center = {}
  330. mathUtil.clonePoint(data.center, icon.center)
  331. data.points = [].concat(icon.points)
  332. data.radius = icon.radius
  333. return data
  334. }
  335. getDataForTitle(title) {
  336. const data = {}
  337. data.id = title.vectorId
  338. data.type = title.geoType
  339. data.value = title.value
  340. return data
  341. }
  342. getDataForImage(image) {
  343. const data = {}
  344. data.id = image.vectorId
  345. data.type = image.geoType
  346. data.src = image.src
  347. return data
  348. }
  349. getDataForCompass(compass) {
  350. const data = {}
  351. data.id = compass.vectorId
  352. data.type = compass.geoType
  353. data.angle = compass.angle
  354. return data
  355. }
  356. // getDataForAngle(angle) {
  357. // return angle
  358. // }
  359. // getDataForRes(res) {
  360. // return res
  361. // }
  362. }
  363. const historyUtil = new HistoryUtil()
  364. export { historyUtil }