FloorplanService.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. import { floorplanData } from '../FloorplanData'
  2. import { coordinate } from '../Coordinate.js'
  3. import Constant from '../Constant'
  4. export class FloorplanService {
  5. constructor() {
  6. this.currentId = 0 // 当前可用id
  7. this.currentFloor = 0 // 当前楼层,第一层是0
  8. this.angle = 0 //旋转角度
  9. }
  10. setCurrentId(id) {
  11. this.currentId = id
  12. }
  13. getCurrentId() {
  14. return this.currentId
  15. }
  16. updateCurrentId() {
  17. ++this.currentId
  18. }
  19. setCurrentFloor(floor) {
  20. if (floorplanData.floors.length == 1) {
  21. this.currentFloor = 0
  22. } else {
  23. this.currentFloor = floor
  24. }
  25. }
  26. getCurrentFloor() {
  27. return this.currentFloor
  28. }
  29. getCompass() {
  30. return floorplanData.compass
  31. }
  32. setCompass(angle) {
  33. floorplanData.compass = angle
  34. }
  35. getFloorNum() {
  36. return floorplanData.floors.length
  37. }
  38. initFloor(floorNum) {
  39. floorplanData.initFloor(floorNum)
  40. }
  41. getFloors() {
  42. return floorplanData.floors
  43. }
  44. getPoint(pointId, floor) {
  45. if (floor == null || typeof floor == 'undefined') {
  46. floor = this.currentFloor
  47. }
  48. return floorplanData.floors[floor].points[pointId]
  49. }
  50. deletePoint(pointId, wallId, floor) {
  51. if (floor == null || typeof floor == 'undefined') {
  52. floor = this.currentFloor
  53. }
  54. let point = this.getPoint(pointId)
  55. //有可能先删除墙,导致点没了
  56. if (point) {
  57. if (Object.keys(point.parent).length == 0) {
  58. point = null
  59. delete floorplanData.floors[floor].points[pointId]
  60. } else if (Object.keys(point.parent).length == 1 && !wallId) {
  61. delete floorplanData.floors[floor].points[pointId]
  62. } else if (Object.keys(point.parent).length == 1 && point.parent[wallId]) {
  63. delete floorplanData.floors[floor].points[pointId]
  64. } else if (Object.keys(point.parent).length == 1 && !point.parent[wallId]) {
  65. return
  66. } else {
  67. delete point.parent[wallId]
  68. }
  69. }
  70. }
  71. getWall(wallId, floor) {
  72. if (floor == null || typeof floor == 'undefined') {
  73. floor = this.currentFloor
  74. }
  75. return floorplanData.floors[floor].walls[wallId]
  76. }
  77. deleteWall(wallId, floor) {
  78. if (floor == null || typeof floor == 'undefined') {
  79. floor = this.currentFloor
  80. }
  81. let wall = this.getWall(wallId, floor)
  82. this.deletePoint(wall.start, wallId, floor)
  83. this.deletePoint(wall.end, wallId, floor)
  84. delete floorplanData.floors[floor].walls[wallId]
  85. }
  86. getAngle() {
  87. return this.angle
  88. }
  89. setAngle(angle) {
  90. this.angle = angle
  91. }
  92. getFloorData(floor) {
  93. if (floor == null || typeof floor == 'undefined') {
  94. floor = this.currentFloor
  95. }
  96. return floorplanData.floors[floor]
  97. }
  98. getWalls(floor) {
  99. if (floor == null || typeof floor == 'undefined') {
  100. floor = this.currentFloor
  101. }
  102. return floorplanData.floors[floor].walls
  103. }
  104. getPoints(floor) {
  105. if (floor == null || typeof floor == 'undefined') {
  106. floor = this.currentFloor
  107. }
  108. return floorplanData.floors[floor].points
  109. }
  110. addWall(wall, floor) {
  111. if (floor == null || typeof floor == 'undefined') {
  112. floor = this.currentFloor
  113. }
  114. floorplanData.floors[floor].walls[wall.vectorId] = wall
  115. }
  116. addPoint(point, floor) {
  117. if (floor == null || typeof floor == 'undefined') {
  118. floor = this.currentFloor
  119. }
  120. floorplanData.floors[floor].points[point.vectorId] = point
  121. }
  122. addRectangle(rectangle,floor){
  123. if (floor == null || typeof floor == 'undefined') {
  124. floor = this.currentFloor
  125. }
  126. floorplanData.floors[floor].rectangles[rectangle.vectorId] = rectangle
  127. }
  128. getRectangle(rectangleId, floor) {
  129. if (floor == null || typeof floor == 'undefined') {
  130. floor = this.currentFloor
  131. }
  132. return floorplanData.floors[floor].rectangles[rectangleId]
  133. }
  134. deleteRectangle(rectangleId, floor){
  135. if (floor == null || typeof floor == 'undefined') {
  136. floor = this.currentFloor
  137. }
  138. let rectangle = this.getRectangle(rectangleId, floor)
  139. rectangle = null
  140. delete floorplanData.floors[floor].rectangles[rectangleId]
  141. }
  142. addCircle(circle,floor){
  143. if (floor == null || typeof floor == 'undefined') {
  144. floor = this.currentFloor
  145. }
  146. floorplanData.floors[floor].circles[circle.vectorId] = circle
  147. }
  148. getCircle(circleId, floor) {
  149. if (floor == null || typeof floor == 'undefined') {
  150. floor = this.currentFloor
  151. }
  152. return floorplanData.floors[floor].circles[circleId]
  153. }
  154. deleteCircle(circleId, floor){
  155. if (floor == null || typeof floor == 'undefined') {
  156. floor = this.currentFloor
  157. }
  158. let circle = this.getCircle(circleId, floor)
  159. circle = null
  160. delete floorplanData.floors[floor].circles[circleId]
  161. }
  162. addArrow(arrow,floor){
  163. if (floor == null || typeof floor == 'undefined') {
  164. floor = this.currentFloor
  165. }
  166. floorplanData.floors[floor].arrows[arrow.vectorId] = arrow
  167. }
  168. getArrow(arrowId, floor) {
  169. if (floor == null || typeof floor == 'undefined') {
  170. floor = this.currentFloor
  171. }
  172. return floorplanData.floors[floor].arrows[arrowId]
  173. }
  174. deleteArrow(arrowId, floor){
  175. if (floor == null || typeof floor == 'undefined') {
  176. floor = this.currentFloor
  177. }
  178. let arrow = this.getArrow(arrowId, floor)
  179. arrow = null
  180. delete floorplanData.floors[floor].arrows[arrowId]
  181. }
  182. addIcon(icon,floor){
  183. if (floor == null || typeof floor == 'undefined') {
  184. floor = this.currentFloor
  185. }
  186. floorplanData.floors[floor].icons[icon.vectorId] = icon
  187. }
  188. getIcon(iconId, floor) {
  189. if (floor == null || typeof floor == 'undefined') {
  190. floor = this.currentFloor
  191. }
  192. return floorplanData.floors[floor].icons[iconId]
  193. }
  194. deleteIcon(iconId, floor){
  195. if (floor == null || typeof floor == 'undefined') {
  196. floor = this.currentFloor
  197. }
  198. let icon = this.getIcon(iconId, floor)
  199. icon = null
  200. delete floorplanData.floors[floor].icons[iconId]
  201. }
  202. addSign(sign, floor) {
  203. if (floor == null || typeof floor == 'undefined') {
  204. floor = this.currentFloor
  205. }
  206. floorplanData.floors[floor].signs[sign.vectorId] = sign
  207. }
  208. getSign(signId, floor) {
  209. if (floor == null || typeof floor == 'undefined') {
  210. floor = this.currentFloor
  211. }
  212. return floorplanData.floors[floor].signs[signId]
  213. }
  214. deleteSign(signId, floor) {
  215. if (floor == null || typeof floor == 'undefined') {
  216. floor = this.currentFloor
  217. }
  218. let sign = this.getSign(signId, floor)
  219. sign = null
  220. delete floorplanData.floors[floor].signs[signId]
  221. }
  222. addTag(tag, floor) {
  223. if (floor == null || typeof floor == 'undefined') {
  224. floor = this.currentFloor
  225. }
  226. floorplanData.floors[floor].tags[tag.vectorId] = tag
  227. }
  228. getTag(tagId, floor) {
  229. if (floor == null || typeof floor == 'undefined') {
  230. floor = this.currentFloor
  231. }
  232. return floorplanData.floors[floor].tags[tagId]
  233. }
  234. deleteTag(tagId, floor) {
  235. if (floor == null || typeof floor == 'undefined') {
  236. floor = this.currentFloor
  237. }
  238. let tag = this.getTag(tagId, floor)
  239. tag = null
  240. delete floorplanData.floors[floor].tags[tagId]
  241. }
  242. getTags(floor) {
  243. if (floor == null || typeof floor == 'undefined') {
  244. floor = this.currentFloor
  245. }
  246. return floorplanData.floors[floor].tags
  247. }
  248. addTable(table, floor) {
  249. if (floor == null || typeof floor == 'undefined') {
  250. floor = this.currentFloor
  251. }
  252. floorplanData.floors[floor].tables[table.vectorId] = table
  253. }
  254. getTable(tableId, floor) {
  255. if (floor == null || typeof floor == 'undefined') {
  256. floor = this.currentFloor
  257. }
  258. return floorplanData.floors[floor].tables[tableId]
  259. }
  260. deleteTable(tableId, floor) {
  261. if (floor == null || typeof floor == 'undefined') {
  262. floor = this.currentFloor
  263. }
  264. let table = this.getTable(tableId, floor)
  265. table = null
  266. delete floorplanData.floors[floor].tables[tableId]
  267. }
  268. getTables(floor) {
  269. if (floor == null || typeof floor == 'undefined') {
  270. floor = this.currentFloor
  271. }
  272. return floorplanData.floors[floor].tables
  273. }
  274. addCell(cell, floor) {
  275. if (floor == null || typeof floor == 'undefined') {
  276. floor = this.currentFloor
  277. }
  278. floorplanData.floors[floor].cells[cell.vectorId] = cell
  279. }
  280. getCell(cellId, floor) {
  281. if (floor == null || typeof floor == 'undefined') {
  282. floor = this.currentFloor
  283. }
  284. return floorplanData.floors[floor].cells[cellId]
  285. }
  286. deleteCell(cellId, floor) {
  287. if (floor == null || typeof floor == 'undefined') {
  288. floor = this.currentFloor
  289. }
  290. let cell = this.getCell(cellId, floor)
  291. cell = null
  292. delete floorplanData.floors[floor].cells[cellId]
  293. }
  294. getCells(floor) {
  295. if (floor == null || typeof floor == 'undefined') {
  296. floor = this.currentFloor
  297. }
  298. return floorplanData.floors[floor].cells
  299. }
  300. getRectangles(floor) {
  301. if (floor == null || typeof floor == 'undefined') {
  302. floor = this.currentFloor
  303. }
  304. return floorplanData.floors[floor].rectangles
  305. }
  306. getCircles(floor) {
  307. if (floor == null || typeof floor == 'undefined') {
  308. floor = this.currentFloor
  309. }
  310. return floorplanData.floors[floor].circles
  311. }
  312. getArrows(floor) {
  313. if (floor == null || typeof floor == 'undefined') {
  314. floor = this.currentFloor
  315. }
  316. return floorplanData.floors[floor].arrows
  317. }
  318. getIcons(floor) {
  319. if (floor == null || typeof floor == 'undefined') {
  320. floor = this.currentFloor
  321. }
  322. return floorplanData.floors[floor].icons
  323. }
  324. getSigns(floor) {
  325. if (floor == null || typeof floor == 'undefined') {
  326. floor = this.currentFloor
  327. }
  328. return floorplanData.floors[floor].signs
  329. }
  330. clear() {
  331. if (floorplanData.floors[this.currentFloor]) {
  332. floorplanData.floors[this.currentFloor].points = {}
  333. floorplanData.floors[this.currentFloor].walls = {}
  334. floorplanData.floors[this.currentFloor].rectangles = {}
  335. floorplanData.floors[this.currentFloor].circles = {}
  336. floorplanData.floors[this.currentFloor].tags = {}
  337. floorplanData.floors[this.currentFloor].tables = {}
  338. floorplanData.floors[this.currentFloor].cells = {}
  339. floorplanData.floors[this.currentFloor].signs = {}
  340. floorplanData.floors[this.currentFloor].arrows = {}
  341. floorplanData.floors[this.currentFloor].icons = []
  342. }
  343. }
  344. deleteFloorData() {
  345. floorplanData.floors = []
  346. }
  347. }
  348. const floorplanService = new FloorplanService()
  349. export { floorplanService }