MoveWall.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. import { wallService } from '../Service/WallService'
  2. import { floorplanService } from '../Service/FloorplanService'
  3. import Constant from '../Constant'
  4. import { mathUtil } from '../MathUtil'
  5. import { elementService } from '../Service/ElementService'
  6. import { coordinate } from '../Coordinate'
  7. export default class MoveWall {
  8. constructor() {
  9. this.needUpdateRoom = false //是否重新计算房间
  10. this.startMoving = false
  11. this.moveFlag = false
  12. //拖拽墙角的时候,墙角的父亲与其他墙角相交
  13. this.adsorbPointWalls = {}
  14. //拖拽墙角的时候,该墙角与其他墙面相交
  15. this.splitWallId = null
  16. }
  17. // 测试要考虑pointId拖拽到包含他的所有墙的另一头
  18. // 这个函数不会删除/拆分/合并墙或者点
  19. movePoint(pointId, position, modifyPoint) {
  20. let point = floorplanService.getPoint(pointId)
  21. let linkedPointId = null
  22. let linkedWallId = null
  23. if (modifyPoint != null) {
  24. position = {
  25. x: modifyPoint.x,
  26. y: modifyPoint.y,
  27. }
  28. linkedPointId = modifyPoint.linkedPointId
  29. linkedWallId = modifyPoint.linkedWallId
  30. }
  31. this.needUpdateRoom = false
  32. this.adsorbPointWalls = {}
  33. this.splitWallId = null
  34. let flag = this.canMoveForPoint(pointId, position, linkedPointId, linkedWallId)
  35. if (!flag) {
  36. if (this.splitWallId == null && Object.keys(this.adsorbPointWalls).length > 0) {
  37. //要吸附一下
  38. const parent = point.parent
  39. const wall = floorplanService.getWall(Object.keys(parent)[0])
  40. const otherPointId = wall.getOtherPointId(pointId)
  41. let otherPoint = floorplanService.getPoint(otherPointId)
  42. let modifyPoint = floorplanService.getPoint(Object.keys(this.adsorbPointWalls)[0])
  43. let line = mathUtil.createLine1(otherPoint, modifyPoint)
  44. position = mathUtil.getJoinLinePoint(position, line)
  45. point.setPosition(position)
  46. }
  47. return false
  48. }
  49. let newPosition = null
  50. if (modifyPoint == null) {
  51. //90°或者180°纠正
  52. //不考虑当前角度
  53. //当前点的parent只有一个,考虑邻居点
  54. let neighPoints = wallService.getNeighPoints(pointId)
  55. if (neighPoints.length == 1) {
  56. newPosition = elementService.checkAngle(position, neighPoints[0].vectorId, pointId)
  57. }
  58. //当前点的parent有两个
  59. else if (neighPoints.length == 2) {
  60. newPosition = elementService.checkAngle(position, neighPoints[0].vectorId, pointId)
  61. if (!newPosition) {
  62. newPosition = elementService.checkAngle(position, neighPoints[1].vectorId, pointId)
  63. }
  64. // let angle = mathUtil.Angle(position, neighPoints[0], neighPoints[1])
  65. // if (Math.abs((angle / Math.PI) * 180 - 90) < 5) {
  66. // let line = mathUtil.createLine1(position, neighPoints[0])
  67. // let join = mathUtil.getJoinLinePoint(neighPoints[1], line)
  68. // if (join) {
  69. // mathUtil.clonePoint(position, join)
  70. // }
  71. // } else if (Math.abs((angle / Math.PI) * 180) < 5 || Math.abs((angle / Math.PI) * 180 - 180) < 5) {
  72. // let line = mathUtil.createLine1(neighPoints[0], neighPoints[1])
  73. // let join = mathUtil.getJoinLinePoint(position, line)
  74. // if (join) {
  75. // mathUtil.clonePoint(position, join)
  76. // }
  77. // }
  78. }
  79. if (newPosition) {
  80. flag = this.canMoveForPoint(pointId, newPosition, linkedPointId, linkedWallId)
  81. if (!flag) {
  82. return false
  83. }
  84. mathUtil.clonePoint(position, newPosition)
  85. }
  86. point.setPosition(position)
  87. }
  88. // 与别的墙角重合
  89. else if (modifyPoint.hasOwnProperty('linkedPointId') && modifyPoint.linkedPointId != null) {
  90. const wallId = wallService.getWallId(pointId, modifyPoint.linkedPointId)
  91. // pointId与linkedPointId属于同一堵墙,不允许,所以不移动
  92. if (wallId != null) {
  93. return false
  94. } else {
  95. point.setPosition(modifyPoint)
  96. this.needUpdateRoom = true
  97. }
  98. }
  99. // 与别的墙面重合
  100. // 如果墙面的交点与其余墙角的距离过短,那也不允许拖动
  101. else if (modifyPoint.hasOwnProperty('linkedWallId')) {
  102. const wall = floorplanService.getWall(modifyPoint.linkedWallId)
  103. const startPoint = floorplanService.getPoint(wall.start)
  104. const endPoint = floorplanService.getPoint(wall.end)
  105. // 与其余墙角的距离过短,不允许拖动
  106. if (mathUtil.getDistance(startPoint, position) < Constant.minAdsorb || mathUtil.getDistance(endPoint, position) < Constant.minAdsorb) {
  107. return false
  108. }
  109. point.setPosition(modifyPoint)
  110. this.needUpdateRoom = true
  111. } else {
  112. if (modifyPoint.hasOwnProperty('linkedPointIdX') && modifyPoint.linkedPointIdX) {
  113. //const linkedPointX = floorplanService.getPoint(modifyPoint.linkedPointIdX)
  114. //elementService.setCheckLinesX(position, linkedPointX)
  115. point.setPosition(position)
  116. }
  117. if (modifyPoint.hasOwnProperty('linkedPointIdY') && modifyPoint.linkedPointIdY) {
  118. //const linkedPointY = floorplanService.getPoint(modifyPoint.linkedPointIdY)
  119. //elementService.setCheckLinesY(position, linkedPointY)
  120. point.setPosition(position)
  121. }
  122. }
  123. return true
  124. }
  125. // 拖拽墙面
  126. moveWallPlane(wallId, dx, dy) {
  127. // 1表示可以继续移动,2表示不能移动(启动距离还不够),3表示wallId被删除了,4表示重新开始移动(需要达到一定距离才能启动),5表示不能移动(不合适)
  128. let MoveState = 1
  129. let wall = floorplanService.getWall(wallId)
  130. let startPointId = wall.start
  131. let endPointId = wall.end
  132. let startPoint = floorplanService.getPoint(wall.start)
  133. let endPoint = floorplanService.getPoint(wall.end)
  134. // 不考虑约束的情况,得到移动后的坐标
  135. const newpts = this.getNewPointsForMoveWall(wallId, dx, dy)
  136. let newLine = mathUtil.createLine1(newpts.point1, newpts.point2)
  137. // 获取约束信息,包括:是否新建墙,受约束的侧墙
  138. const limit = this.getTwoLimitInfos(wallId, newLine)
  139. this.needUpdateRoom = false
  140. // 不考虑吸附的情况下,经过约束条件后,得到的新的移动后的坐标
  141. let virtualStartPoint = mathUtil.getIntersectionPoint(newLine, limit.startLimitLine)
  142. let virtualEndPoint = mathUtil.getIntersectionPoint(newLine, limit.endLimitLine)
  143. // 刚刚开始移动的时候,或者吸附后再移动的时候,都需要积累一点移动距离才能真正开始移动
  144. if (!this.startMoving && (mathUtil.getDistance(startPoint, virtualStartPoint) < Constant.minAdsorb || mathUtil.getDistance(endPoint, virtualEndPoint) < Constant.minAdsorb)) {
  145. this.moveFlag = false
  146. MoveState = 2
  147. return MoveState
  148. }
  149. this.startMoving = true
  150. // 判断是否会吸附到邻居墙的另一头端点,同时确保新的坐标在邻居墙内
  151. let startInfo = this.updateVirtualPosition(wall.start, virtualStartPoint, limit.startWallId, limit.newStartWallId)
  152. let endInfo = this.updateVirtualPosition(wall.end, virtualEndPoint, limit.endWallId, limit.newEndWallId)
  153. if (startInfo == null || endInfo == null) {
  154. this.moveFlag = false
  155. MoveState = 2
  156. this.startMoving = false
  157. return MoveState
  158. }
  159. // 判断wallId的 1端/2端 吸附后,是否和别的墙重合
  160. let coincideFlag = false
  161. // wallId的长度,可能会很短,要删除
  162. let distance = null
  163. // 如果一头被吸附,另一头的坐标还要再次调整
  164. if (startInfo.adsorb && !endInfo.adsorb) {
  165. // 先更新newLine
  166. newLine = mathUtil.createLine3(newLine, startInfo.virtualPosition)
  167. // 需要判断夹角,如果接近0,则不能移动
  168. const flag = this.isOKForTwoSegmentsAngle(startInfo.adsorbPointId, wall.start, wall.end)
  169. if (!flag) {
  170. this.moveFlag = false
  171. MoveState = 5
  172. return MoveState
  173. }
  174. // 更新virtualEndPoint
  175. virtualEndPoint = mathUtil.getIntersectionPoint(newLine, limit.endLimitLine)
  176. // 再次判断是否吸附
  177. endInfo = this.updateVirtualPosition(wall.end, virtualEndPoint, limit.endWallId, limit.newEndWallId)
  178. if (endInfo == null) {
  179. endInfo = {
  180. adsorb: false,
  181. adsorbPointId: null,
  182. virtualPosition: virtualEndPoint,
  183. }
  184. }
  185. // 一头吸附后,wallId可能和别的墙重合
  186. coincideFlag = this.isCoincideForAdsorbOne(wall.start, startInfo.adsorbPointId, wallId)
  187. distance = mathUtil.getDistance(startInfo.virtualPosition, virtualEndPoint)
  188. MoveState = 4
  189. this.needUpdateRoom = true
  190. this.startMoving = false
  191. } else if (!startInfo.adsorb && endInfo.adsorb) {
  192. newLine = mathUtil.createLine3(newLine, endInfo.virtualPosition)
  193. // 需要判断夹角,如果接近0,则不能移动
  194. const flag = this.isOKForTwoSegmentsAngle(endInfo.adsorbPointId, wall.end, wall.start)
  195. if (!flag) {
  196. this.moveFlag = false
  197. MoveState = 5
  198. return MoveState
  199. }
  200. virtualStartPoint = mathUtil.getIntersectionPoint(newLine, limit.startLimitLine)
  201. startInfo = this.updateVirtualPosition(wall.start, virtualStartPoint, limit.startWallId, limit.newStartWallId)
  202. if (startInfo == null) {
  203. startInfo = {
  204. adsorb: false,
  205. adsorbPointId: null,
  206. virtualPosition: virtualStartPoint,
  207. }
  208. }
  209. coincideFlag = this.isCoincideForAdsorbOne(wall.end, endInfo.adsorbPointId, wallId)
  210. distance = mathUtil.getDistance(endInfo.virtualPosition, virtualStartPoint)
  211. MoveState = 4
  212. this.needUpdateRoom = true
  213. this.startMoving = false
  214. }
  215. // 两头同时吸附呢,wallId可能和别的墙重合
  216. if (startInfo && endInfo && startInfo.adsorb && endInfo.adsorb) {
  217. coincideFlag = this.isCoincideForAdsorbOne2(wallId, startInfo.adsorbPointId, endInfo.adsorbPointId)
  218. distance = mathUtil.getDistance(startInfo.virtualPosition, endInfo.virtualPosition)
  219. this.startMoving = false
  220. if (coincideFlag) {
  221. this.moveFlag = false
  222. MoveState = 5
  223. return MoveState
  224. }
  225. MoveState = 4
  226. this.needUpdateRoom = true
  227. } else {
  228. distance = mathUtil.getDistance(virtualStartPoint, virtualEndPoint)
  229. if (distance < Constant.minAdsorb) {
  230. // 执行deleteWallForLinked后start和end会变,所以提前保存
  231. this.deleteWallForLinked(wallId)
  232. startPoint = floorplanService.getPoint(startPointId)
  233. endPoint = floorplanService.getPoint(endPointId)
  234. if (!startPoint || !endPoint) {
  235. this.moveFlag = false
  236. MoveState = 3
  237. this.needUpdateRoom = true
  238. return MoveState
  239. }
  240. if (
  241. (Object.keys(startPoint.parent).length > 1 && Object.keys(endPoint.parent).length == 1) ||
  242. (Object.keys(startPoint.parent).length == 1 && Object.keys(endPoint.parent).length == 1)
  243. ) {
  244. wallService.moveTo(endPointId, startPointId)
  245. } else if (Object.keys(startPoint.parent).length == 1 && Object.keys(endPoint.parent).length > 1) {
  246. wallService.moveTo(startPointId, endPointId)
  247. }
  248. this.moveFlag = false
  249. MoveState = 3
  250. this.needUpdateRoom = true
  251. return MoveState
  252. }
  253. }
  254. startPointId = wall.start
  255. endPointId = wall.end
  256. // 是否交叉
  257. const crossFlag = this.isOKForCrossForMoveWall(virtualStartPoint, virtualEndPoint, wallId, startPointId, endPointId, startInfo.adsorbPointId, endInfo.adsorbPointId)
  258. // ok
  259. if (!crossFlag) {
  260. MoveState = 2
  261. this.moveFlag = false
  262. this.startMoving = false
  263. return MoveState
  264. }
  265. // 要删除墙了
  266. if (coincideFlag || (distance != null && distance < Constant.minAdsorb)) {
  267. this.deleteWallForLinked(wallId)
  268. MoveState = 3
  269. // 删除完墙,邻居墙可能会合并
  270. wallService.mergeWallForPoint(startPointId)
  271. wallService.mergeWallForPoint(endPointId)
  272. this.moveFlag = false
  273. this.needUpdateRoom = true
  274. return MoveState
  275. } else {
  276. // 要删除墙了
  277. const join = mathUtil.getIntersectionPoint3(startPoint, virtualStartPoint, endPoint, virtualEndPoint)
  278. if (join != null) {
  279. startPoint.setPosition(join)
  280. endPoint.setPosition(join)
  281. wallService.moveTo(startPointId, endPointId)
  282. MoveState = 3
  283. this.moveFlag = false
  284. this.needUpdateRoom = true
  285. return MoveState
  286. }
  287. }
  288. let overlapFlag = false
  289. if (!limit.newStartWallId && startInfo.adsorbPointId) {
  290. overlapFlag = wallService.isOverlapForMergePoint(startPointId, startInfo.adsorbPointId)
  291. } else if (!limit.newEndWallId && endInfo.adsorbPointId) {
  292. overlapFlag = wallService.isOverlapForMergePoint(endPointId, endInfo.adsorbPointId)
  293. }
  294. if (overlapFlag) {
  295. this.moveFlag = false
  296. MoveState = 5
  297. return MoveState
  298. }
  299. // 到了这一步,端点的新坐标已经确定了,这里开始更新端点坐标
  300. // 这里需要升级优化,因为 updatePointForMoveWall方法里也更新了edge,这个其实不需要的。
  301. this.updatePointForMoveWall(wallId, startPointId, startInfo, limit.startWallId, limit.newStartWallId)
  302. this.updatePointForMoveWall(wallId, endPointId, endInfo, limit.endWallId, limit.newEndWallId)
  303. wall = floorplanService.getWall(wallId)
  304. if (wall == null) {
  305. MoveState = 3
  306. this.moveFlag = false
  307. this.needUpdateRoom = true
  308. // console.log(271)
  309. return MoveState
  310. }
  311. if (MoveState == 1) {
  312. this.moveFlag = true
  313. } else {
  314. this.moveFlag = false
  315. }
  316. return MoveState
  317. }
  318. //拖拽墙角/墙面,被其他墙角吸附
  319. updateForAbsorbWallPoints() {
  320. if (Object.keys(this.adsorbPointWalls).length == 0) {
  321. return
  322. } else if (Object.keys(this.adsorbPointWalls).length == 2) {
  323. debugger
  324. }
  325. let joins = []
  326. let wallId = null
  327. for (let key in this.adsorbPointWalls) {
  328. let point = floorplanService.getPoint(key)
  329. joins.push({
  330. join: point,
  331. pointId: key,
  332. })
  333. wallId = this.adsorbPointWalls[key]
  334. }
  335. const wall = floorplanService.getWall(wallId)
  336. const startPoint = floorplanService.getPoint(wall.start)
  337. function sortNumber(a, b) {
  338. return mathUtil.getDistance(startPoint, a.join) - mathUtil.getDistance(startPoint, b.join)
  339. }
  340. joins = joins.sort(sortNumber.bind(this))
  341. for (let i = 0; i < joins.length; ++i) {
  342. const info = joins[i]
  343. const join = info.join
  344. const pointId = info.pointId
  345. wallService.splitWall(wallId, pointId, 'end')
  346. }
  347. }
  348. getNewPointsForMoveWall(wallId, dx, dy) {
  349. dx = dx / coordinate.res * Constant.defaultZoom/coordinate.zoom
  350. dy = -dy / coordinate.res * Constant.defaultZoom/coordinate.zoom
  351. const wall = floorplanService.getWall(wallId)
  352. const startPoint = floorplanService.getPoint(wall.start)
  353. const endPoint = floorplanService.getPoint(wall.end)
  354. const p1 = { x: startPoint.x + dx, y: startPoint.y + dy }
  355. const p2 = { x: endPoint.x + dx, y: endPoint.y + dy }
  356. return {
  357. point1: p1,
  358. point2: p2,
  359. }
  360. }
  361. getTwoLimitInfos(wallId, newLine) {
  362. const wall = floorplanService.getWall(wallId)
  363. const startPoint = floorplanService.getPoint(wall.start)
  364. const endPoint = floorplanService.getPoint(wall.end)
  365. let startLimitLine, endLimitLine, info
  366. const wallLine = mathUtil.createLine1(startPoint, endPoint)
  367. const limitInfos = {}
  368. limitInfos.newStartWallId = false // 不需要新建墙
  369. limitInfos.newEndWallId = false // 不需要新建墙
  370. // 先处理start
  371. if (Object.keys(startPoint.parent).length == 1) {
  372. startLimitLine = mathUtil.getVerticalLine(wallLine, startPoint)
  373. limitInfos.startWallId = null
  374. } else if (Object.keys(startPoint.parent).length == 2) {
  375. let tempWall
  376. if (Object.keys(startPoint.parent)[0] == wallId) {
  377. tempWall = floorplanService.getWall(Object.keys(startPoint.parent)[1])
  378. } else if (Object.keys(startPoint.parent)[1] == wallId) {
  379. tempWall = floorplanService.getWall(Object.keys(startPoint.parent)[0])
  380. }
  381. if (!tempWall) {
  382. console.error(352)
  383. }
  384. const angle = wallService.AngleForWall(tempWall.vectorId, wallId)
  385. startLimitLine = wallService.getLine(tempWall)
  386. limitInfos.startWallId = tempWall.vectorId
  387. if (angle > (Constant.maxAngle / 180) * Math.PI) {
  388. startLimitLine = mathUtil.getVerticalLine(wallLine, startPoint)
  389. limitInfos.startWallId = null
  390. limitInfos.newStartWallId = true
  391. }
  392. } else {
  393. let tempWall, tempWallId
  394. info = wallService.wallIdForMinAngle(wall.start, wallId)
  395. const wall1 = floorplanService.getWall(info.min0.wallId)
  396. const startPoint1 = floorplanService.getPoint(wall1.start)
  397. const endPoint1 = floorplanService.getPoint(wall1.end)
  398. const wall2 = floorplanService.getWall(info.min1.wallId)
  399. const startPoint2 = floorplanService.getPoint(wall2.start)
  400. const endPoint2 = floorplanService.getPoint(wall2.end)
  401. const join1 = mathUtil.getIntersectionPoint4(startPoint1, endPoint1, newLine)
  402. const join2 = mathUtil.getIntersectionPoint4(startPoint2, endPoint2, newLine)
  403. // 取角度大的
  404. if (join1 == null && join2 == null) {
  405. let angle0 = wallService.AngleForWall(wallId, info.min0.wallId)
  406. let angle1 = wallService.AngleForWall(wallId, info.min1.wallId)
  407. if (angle0 > Math.PI) {
  408. angle0 = Math.PI - angle0
  409. }
  410. if (angle1 > Math.PI) {
  411. angle1 = Math.PI - angle1
  412. }
  413. if (angle0 < angle1) {
  414. tempWallId = info.min0.wallId
  415. } else {
  416. tempWallId = info.min1.wallId
  417. }
  418. limitInfos.newStartWallId = true
  419. }
  420. // 取角度小的
  421. else if (join1 != null && join2 != null) {
  422. if (info.min0.angle < info.min1.angle) {
  423. tempWallId = info.min0.wallId
  424. } else {
  425. tempWallId = info.min1.wallId
  426. }
  427. } else if (join1 == null && join2 != null) {
  428. tempWallId = info.min1.wallId
  429. } else if (join1 != null && join2 == null) {
  430. tempWallId = info.min0.wallId
  431. }
  432. limitInfos.startWallId = tempWallId
  433. tempWall = floorplanService.getWall(tempWallId)
  434. const angle = wallService.AngleForWall(tempWallId, wallId)
  435. startLimitLine = wallService.getLine(tempWall)
  436. if (angle > (Constant.maxAngle / 180) * Math.PI) {
  437. startLimitLine = mathUtil.getVerticalLine(wallLine, startPoint)
  438. limitInfos.startWallId = null
  439. limitInfos.newStartWallId = true
  440. }
  441. }
  442. // 再处理end
  443. if (Object.keys(endPoint.parent).length == 1) {
  444. endLimitLine = mathUtil.getVerticalLine(wallLine, endPoint)
  445. limitInfos.endWallId = null
  446. } else if (Object.keys(endPoint.parent).length == 2) {
  447. let tempWall
  448. if (Object.keys(endPoint.parent)[0] == wallId) {
  449. tempWall = floorplanService.getWall(Object.keys(endPoint.parent)[1])
  450. } else if (Object.keys(endPoint.parent)[1] == wallId) {
  451. tempWall = floorplanService.getWall(Object.keys(endPoint.parent)[0])
  452. }
  453. const angle = wallService.AngleForWall(tempWall.vectorId, wallId)
  454. endLimitLine = wallService.getLine(tempWall)
  455. limitInfos.endWallId = tempWall.vectorId
  456. if (angle > (Constant.maxAngle / 180) * Math.PI) {
  457. endLimitLine = mathUtil.getVerticalLine(wallLine, endPoint)
  458. limitInfos.endWallId = null
  459. limitInfos.newEndWallId = true
  460. }
  461. } else {
  462. let tempWall, tempWallId
  463. info = wallService.wallIdForMinAngle(wall.end, wallId)
  464. const wall1 = floorplanService.getWall(info.min0.wallId)
  465. const startPoint1 = floorplanService.getPoint(wall1.start)
  466. const endPoint1 = floorplanService.getPoint(wall1.end)
  467. const wall2 = floorplanService.getWall(info.min1.wallId)
  468. const startPoint2 = floorplanService.getPoint(wall2.start)
  469. const endPoint2 = floorplanService.getPoint(wall2.end)
  470. const join1 = mathUtil.getIntersectionPoint4(startPoint1, endPoint1, newLine)
  471. const join2 = mathUtil.getIntersectionPoint4(startPoint2, endPoint2, newLine)
  472. // 取角度大的
  473. if (join1 == null && join2 == null) {
  474. let angle0 = wallService.AngleForWall(wallId, info.min0.wallId)
  475. let angle1 = wallService.AngleForWall(wallId, info.min1.wallId)
  476. if (angle0 > Math.PI) {
  477. angle0 = Math.PI - angle0
  478. }
  479. if (angle1 > Math.PI) {
  480. angle1 = Math.PI - angle1
  481. }
  482. if (angle0 < angle1) {
  483. tempWallId = info.min0.wallId
  484. } else {
  485. tempWallId = info.min1.wallId
  486. }
  487. limitInfos.newEndWallId = true
  488. }
  489. // 取角度小的
  490. else if (join1 != null && join2 != null) {
  491. if (info.min0.angle < info.min1.angle) {
  492. tempWallId = info.min0.wallId
  493. } else {
  494. tempWallId = info.min1.wallId
  495. }
  496. } else if (join1 == null && join2 != null) {
  497. tempWallId = info.min1.wallId
  498. } else if (join1 != null && join2 == null) {
  499. tempWallId = info.min0.wallId
  500. }
  501. limitInfos.endWallId = tempWallId
  502. tempWall = floorplanService.getWall(tempWallId)
  503. const angle = wallService.AngleForWall(tempWallId, wallId)
  504. endLimitLine = wallService.getLine(tempWall)
  505. if (angle > (Constant.maxAngle / 180) * Math.PI) {
  506. endLimitLine = mathUtil.getVerticalLine(wallLine, endPoint)
  507. limitInfos.endWallId = null
  508. limitInfos.newEndWallId = true
  509. }
  510. }
  511. limitInfos.startLimitLine = startLimitLine
  512. limitInfos.endLimitLine = endLimitLine
  513. return limitInfos
  514. }
  515. // 是否可以移动point
  516. // 两个判断:拖拽的墙(可能是多个),一方面不能与其他墙相交,另一方面这些墙之间或者与别的墙之间的角度必须大于Constant.minAngle
  517. canMoveForPoint(pointId, position, linkedPointId, linkedWallId) {
  518. const point = floorplanService.getPoint(pointId)
  519. // 先判断第二点(这些墙之间或者与别的墙之间的角度必须大于MinAngle)
  520. let flag = this.isOKForMinAngleWall(pointId, position)
  521. // 开始考虑第一点
  522. if (flag) {
  523. // 不仅仅角度,还有相交
  524. flag = this.isOKForCross(pointId, position, point.parent, linkedPointId, linkedWallId)
  525. }
  526. return flag
  527. }
  528. isOKForMinAngleWall(pointId, position) {
  529. const point = floorplanService.getPoint(pointId)
  530. const parent = point.parent
  531. const angle = this.getMinAngle(pointId, position)
  532. if (Math.abs(angle) < (Constant.minAngle / 180) * Math.PI) {
  533. return false
  534. }
  535. // 判断邻居点
  536. for (const key in parent) {
  537. const wall = floorplanService.getWall(key)
  538. const otherPointId = wall.getOtherPointId(pointId)
  539. const info = this.getNeighMinAngle(otherPointId, key, position)
  540. if (info && Math.abs(info.angle) < (Constant.minAngle / 180) * Math.PI) {
  541. return false
  542. } else {
  543. const otherPoint = floorplanService.getPoint(otherPointId)
  544. if (mathUtil.getDistance(position, otherPoint) < Constant.minAdsorb) {
  545. return false
  546. }
  547. }
  548. }
  549. return true
  550. }
  551. //点pointId移动到position后,求出最小角度
  552. getMinAngle(pointId, position) {
  553. const point = floorplanService.getPoint(pointId)
  554. const parent = point.parent
  555. let angle = null
  556. if (Object.keys(parent).length == 1) {
  557. return 2 * Math.PI
  558. } else if (Object.keys(parent).length == 2) {
  559. const wall1 = floorplanService.getWall(Object.keys(parent)[0])
  560. const wall2 = floorplanService.getWall(Object.keys(parent)[1])
  561. const otherPointId1 = wall1.getOtherPointId(pointId)
  562. const otherPoint1 = floorplanService.getPoint(otherPointId1)
  563. const otherPointId2 = wall2.getOtherPointId(pointId)
  564. const otherPoint2 = floorplanService.getPoint(otherPointId2)
  565. angle = mathUtil.Angle(position, otherPoint1, otherPoint2)
  566. return angle
  567. } else {
  568. const _position = {
  569. x: position.x + 1,
  570. y: position.y,
  571. }
  572. let angles = []
  573. for (const key in parent) {
  574. const wall = floorplanService.getWall(key)
  575. const otherPointId = wall.getOtherPointId(pointId)
  576. const otherPoint = floorplanService.getPoint(otherPointId)
  577. if (mathUtil.equalPoint(_position, otherPoint)) {
  578. angles.push(0)
  579. continue
  580. } else {
  581. let angle = mathUtil.Angle(position, _position, otherPoint)
  582. // 统一按照逆时针顺序
  583. if (otherPoint.y < position.y) {
  584. angle = 2 * Math.PI - angle
  585. }
  586. angles.push(angle)
  587. }
  588. }
  589. angles = angles.sort(sortNumber)
  590. let minAngle = 2 * Math.PI
  591. for (let i = 0; i < angles.length - 1; ++i) {
  592. for (let j = i + 1; j < angles.length; ++j) {
  593. const _angle = angles[j] - angles[i]
  594. if (_angle < minAngle) {
  595. minAngle = _angle
  596. }
  597. }
  598. }
  599. const angle1 = angles[0]
  600. const angle2 = angles[angles.length - 1]
  601. if (angle1 < Math.PI && angle2 > Math.PI) {
  602. const dAngle = 2 * Math.PI + angle1 - angle2
  603. if (dAngle < minAngle) {
  604. minAngle = dAngle
  605. }
  606. }
  607. return minAngle
  608. }
  609. function sortNumber(a, b) {
  610. return a - b
  611. }
  612. }
  613. // 用于邻居点
  614. // pointId是顶点
  615. // position是wallId相对于pointId另一头的点的坐标,一般发生改变的时候使用这个函数
  616. getNeighMinAngle(otherPointId, wallId, position) {
  617. const point1 = floorplanService.getPoint(otherPointId)
  618. const point2 = {
  619. x: position.x,
  620. y: position.y,
  621. }
  622. let pointId3 = null
  623. let point3 = null
  624. let minAngle = null
  625. let result = null
  626. for (const key in point1.parent) {
  627. if (key == wallId) {
  628. continue
  629. }
  630. const wall = floorplanService.getWall(key)
  631. pointId3 = wall.getOtherPointId(otherPointId)
  632. point3 = floorplanService.getPoint(pointId3)
  633. const angle = mathUtil.Angle(point1, point2, point3)
  634. if (minAngle == null || minAngle > angle) {
  635. minAngle = angle
  636. result = {
  637. angle: minAngle,
  638. pointId: pointId3,
  639. }
  640. }
  641. }
  642. return result
  643. }
  644. // linkedPointId,linkedWallId表示吸附
  645. // wallIds是pointId的parent
  646. isOKForCross(pointId, position, wallIds, linkedPointId, linkedWallId) {
  647. const walls = floorplanService.getWalls()
  648. for (const key in walls) {
  649. if (wallIds.hasOwnProperty(key)) {
  650. continue
  651. } else if (linkedWallId == key) {
  652. continue
  653. }
  654. for (const _key in wallIds) {
  655. //相连就不用考虑了
  656. if (wallService.isWallLink(key, _key)) {
  657. continue
  658. }
  659. const _wall = floorplanService.getWall(_key)
  660. const otherPointId = _wall.getOtherPointId(pointId)
  661. const otherPoint = floorplanService.getPoint(otherPointId)
  662. const flag = this.isOKForCrossTwoWall(position, otherPoint, key, linkedPointId, linkedWallId, _wall.vectorId)
  663. // 交叉
  664. if (!flag) {
  665. this.adsorbPointWalls = {}
  666. return false
  667. }
  668. }
  669. }
  670. //需要吸附了。
  671. if (Object.keys(this.adsorbPointWalls).length > 0) {
  672. return false
  673. } else if (this.splitWallId != null) {
  674. return false
  675. }
  676. // 不交叉
  677. return true
  678. }
  679. // position1表示拖拽的点的坐标(修复过了的)
  680. // position2对应墙的另一头坐标
  681. // wallId表示其余的墙(与position1无关的墙)
  682. isOKForCrossTwoWall(position1, position2, wallId, linkedPointId, linkedWallId, dragWallId) {
  683. const wall = floorplanService.getWall(wallId)
  684. const startPoint = floorplanService.getPoint(wall.start)
  685. const endPoint = floorplanService.getPoint(wall.end)
  686. const join = mathUtil.getIntersectionPoint3(position1, position2, startPoint, endPoint)
  687. if (join && wall.start != linkedPointId && wall.end != linkedPointId) {
  688. // 交叉了
  689. this.splitWallId = wallId
  690. return true
  691. } else {
  692. if (mathUtil.equalPoint(position1, position2)) {
  693. return true
  694. }
  695. let line = mathUtil.createLine1(position1, position2)
  696. let join1 = mathUtil.getJoinLinePoint(startPoint, line)
  697. let join2 = mathUtil.getJoinLinePoint(endPoint, line)
  698. if (mathUtil.getDistance(join1, startPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join1, position1, position2)) {
  699. if (wall.start != linkedPointId) {
  700. // 交叉了
  701. this.adsorbPointWalls[startPoint.vectorId] = dragWallId
  702. //为了找到全部的吸附点,暂时返回true,在外面一层再做判断
  703. return true
  704. }
  705. } else if (mathUtil.getDistance(join2, endPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join2, position1, position2)) {
  706. if (wall.end != linkedPointId) {
  707. // 交叉了
  708. this.adsorbPointWalls[endPoint.vectorId] = dragWallId
  709. //为了找到全部的吸附点,暂时返回true,在外面一层再做判断
  710. return true
  711. }
  712. }
  713. line = mathUtil.createLine1(startPoint, endPoint)
  714. join1 = mathUtil.getJoinLinePoint(position1, line)
  715. join2 = mathUtil.getJoinLinePoint(position2, line)
  716. if (mathUtil.getDistance(join1, position1) < Constant.minAdsorb && mathUtil.PointInSegment(join1, startPoint, endPoint)) {
  717. if (wall.start != linkedPointId && wall.end != linkedPointId && wallId != linkedWallId) {
  718. // 交叉了
  719. //return false
  720. return true
  721. }
  722. } else if (mathUtil.getDistance(join2, position2) < Constant.minAdsorb && mathUtil.PointInSegment(join2, startPoint, endPoint)) {
  723. if (wall.start != linkedPointId && wall.end != linkedPointId && wallId != linkedWallId) {
  724. // 交叉了
  725. //return false
  726. return true
  727. }
  728. }
  729. }
  730. return true
  731. }
  732. isOKForCrossTwoWall2(position1, position2, wallId) {
  733. const wall = floorplanService.getWall(wallId)
  734. const startPoint = floorplanService.getPoint(wall.start)
  735. const endPoint = floorplanService.getPoint(wall.end)
  736. let flag = mathUtil.crossTwoLines(position1, position2, startPoint, endPoint, 0.01)
  737. if (flag) {
  738. // 交叉了
  739. return false
  740. } else {
  741. if (mathUtil.equalPoint(position1, position2)) {
  742. return true
  743. }
  744. flag = this.isCoincide(position1, position2, wallId)
  745. if (!flag) {
  746. return false
  747. }
  748. }
  749. return true
  750. }
  751. isOKForCrossTwoWall3(position1, position2, wallId) {
  752. const wall = floorplanService.getWall(wallId)
  753. const startPoint = floorplanService.getPoint(wall.start)
  754. const endPoint = floorplanService.getPoint(wall.end)
  755. const flag = mathUtil.crossTwoLines(position1, position2, startPoint, endPoint, 0.01)
  756. if (flag) {
  757. // 交叉了
  758. return false
  759. } else {
  760. if (mathUtil.equalPoint(position1, position2)) {
  761. return true
  762. }
  763. let line = mathUtil.createLine1(position1, position2)
  764. let join1 = mathUtil.getJoinLinePoint(startPoint, line)
  765. const join2 = mathUtil.getJoinLinePoint(endPoint, line)
  766. if (mathUtil.getDistance(join1, startPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join1, position1, position2)) {
  767. // 交叉了
  768. return false
  769. } else if (mathUtil.getDistance(join2, endPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join2, position1, position2)) {
  770. // 交叉了
  771. return false
  772. }
  773. line = mathUtil.createLine1(startPoint, endPoint)
  774. join1 = mathUtil.getJoinLinePoint(position1, line)
  775. if (mathUtil.getDistance(join1, position1) < Constant.minAdsorb && wallService.isContain(wall, join1)) {
  776. // 交叉了
  777. return false
  778. }
  779. }
  780. return true
  781. }
  782. isCoincide(position1, position2, wallId) {
  783. const wall = floorplanService.getWall(wallId)
  784. const startPoint = floorplanService.getPoint(wall.start)
  785. const endPoint = floorplanService.getPoint(wall.end)
  786. let line = mathUtil.createLine1(position1, position2)
  787. let join1 = mathUtil.getJoinLinePoint(startPoint, line)
  788. let join2 = mathUtil.getJoinLinePoint(endPoint, line)
  789. if (mathUtil.getDistance(join1, startPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join1, position1, position2)) {
  790. // 交叉了
  791. return false
  792. } else if (mathUtil.getDistance(join2, endPoint) < Constant.minAdsorb && mathUtil.PointInSegment(join2, position1, position2)) {
  793. // 交叉了
  794. return false
  795. }
  796. line = mathUtil.createLine1(startPoint, endPoint)
  797. join1 = mathUtil.getJoinLinePoint(position1, line)
  798. join2 = mathUtil.getJoinLinePoint(position2, line)
  799. if (mathUtil.getDistance(join1, position1) < Constant.minAdsorb && wallService.isContain(wall, join1)) {
  800. // 交叉了
  801. return false
  802. } else if (mathUtil.getDistance(join2, position2) < Constant.minAdsorb && wallService.isContain(wall, join2)) {
  803. // 交叉了
  804. return false
  805. }
  806. return true
  807. }
  808. // 更新virtualPosition(一般是吸附)
  809. updateVirtualPosition(pointId, virtualPosition, limitWallId, needNew) {
  810. const limitWall = floorplanService.getWall(limitWallId)
  811. const point = floorplanService.getPoint(pointId)
  812. let otherPointId, otherPoint
  813. let adsorb = false
  814. // 不需要新建墙
  815. if (!needNew) {
  816. if (limitWall != null) {
  817. otherPointId = limitWall.getOtherPointId(pointId)
  818. otherPoint = floorplanService.getPoint(otherPointId)
  819. // 会吸附另一头
  820. if (
  821. mathUtil.getDistance(virtualPosition, otherPoint) < Constant.minAdsorb ||
  822. (!wallService.isContain(limitWall, virtualPosition) && mathUtil.getDistance(virtualPosition, otherPoint) < mathUtil.getDistance(virtualPosition, point))
  823. ) {
  824. mathUtil.clonePoint(virtualPosition, otherPoint)
  825. adsorb = true
  826. }
  827. }
  828. }
  829. // 需要新建墙
  830. else {
  831. // 新建的墙太短,不允许
  832. if (mathUtil.getDistance(point, virtualPosition) < Constant.minAdsorb) {
  833. return null
  834. }
  835. }
  836. return {
  837. adsorb: adsorb,
  838. adsorbPointId: adsorb ? otherPointId : null,
  839. virtualPosition: virtualPosition,
  840. }
  841. }
  842. // 两条线段的夹角,这两条线段分别有一个端点挨的很近
  843. isOKForTwoSegmentsAngle(pointId, pointId1, pointId2) {
  844. const point = floorplanService.getPoint(pointId)
  845. const point1 = floorplanService.getPoint(pointId1)
  846. const point2 = floorplanService.getPoint(pointId2)
  847. const dx = point.x - point1.x
  848. const dy = point.y - point1.y
  849. const newPoint2 = {
  850. x: dx + point2.x,
  851. y: dy + point2.y,
  852. }
  853. for (const key in point.parent) {
  854. const wall = floorplanService.getWall(key)
  855. const otherPointId = wall.getOtherPointId(pointId)
  856. const otherPoint = floorplanService.getPoint(otherPointId)
  857. const angle = mathUtil.Angle(point, otherPoint, newPoint2)
  858. if (Math.abs(angle) < (Constant.minAngle / 180) * Math.PI) {
  859. return false
  860. }
  861. }
  862. return true
  863. }
  864. // 一头吸附后,是否会重合
  865. // pointId属于wallId,当pointId吸附到adsorbPointId时
  866. isCoincideForAdsorbOne(pointId, adsorbPointId, wallId) {
  867. if (pointId && adsorbPointId) {
  868. const wall = floorplanService.getWall(wallId)
  869. const otherPointId = wall.getOtherPointId(pointId)
  870. const _wallId = wallService.getWallId(otherPointId, adsorbPointId)
  871. if (_wallId != null) {
  872. return true
  873. }
  874. }
  875. return false
  876. }
  877. isCoincideForAdsorbOne2(wallId, adsorbPointId1, adsorbPointId2) {
  878. if (adsorbPointId1 && adsorbPointId2) {
  879. const _wallId = wallService.getWallId(adsorbPointId1, adsorbPointId2)
  880. if (_wallId != null) {
  881. return true
  882. }
  883. // 可能吸附的是两堵墙,但是这两堵墙呈180°
  884. else {
  885. let adsorbPoint = floorplanService.getPoint(adsorbPointId1)
  886. let parent = adsorbPoint.parent
  887. for (const key in parent) {
  888. const angle = wallService.AngleForWall3(wallId, key)
  889. if (Math.abs(angle) < (Constant.minAngle / 180) * Math.PI) {
  890. return true
  891. }
  892. }
  893. adsorbPoint = floorplanService.getPoint(adsorbPointId2)
  894. parent = adsorbPoint.parent
  895. for (const key in parent) {
  896. const angle = wallService.AngleForWall3(wallId, key)
  897. if (Math.abs(angle) < (Constant.minAngle / 180) * Math.PI) {
  898. return true
  899. }
  900. }
  901. }
  902. }
  903. return false
  904. }
  905. // position1和position2表示wall的两个端点坐标(下一步的)
  906. // position3和position4表示wall的start一边的线段(startPoint——virtualStartPoint)
  907. // position5和position6表示wall的end一边的线段(endPoint——virtualEndPoint)
  908. // adsorbPointId1对应start那一头的吸附点
  909. // adsorbPointId2对应end那一头的吸附点
  910. isOKForCrossForMoveWall(position1, position2, wallId, startPointId, endPointId, adsorbPointId1, adsorbPointId2) {
  911. const startPoint = floorplanService.getPoint(startPointId)
  912. const endPoint = floorplanService.getPoint(endPointId)
  913. let flag = true
  914. const walls = floorplanService.getWalls()
  915. for (const key in walls) {
  916. if (key == wallId) {
  917. continue
  918. }
  919. let flag1 = true
  920. let flag2 = true
  921. const _wall = floorplanService.getWall(key)
  922. if (adsorbPointId1 && (adsorbPointId1 == _wall.start || adsorbPointId1 == _wall.end)) {
  923. flag1 = false
  924. }
  925. if (adsorbPointId2 && (adsorbPointId2 == _wall.start || adsorbPointId2 == _wall.end)) {
  926. flag2 = false
  927. }
  928. if (_wall.start == startPointId || _wall.end == startPointId) {
  929. flag1 = false
  930. }
  931. if (_wall.start == endPointId || _wall.end == endPointId) {
  932. flag2 = false
  933. }
  934. // 两头不连
  935. if (flag1 && flag2) {
  936. flag = this.isOKForCrossTwoWall2(position1, position2, key)
  937. }
  938. if (!flag) {
  939. return false
  940. }
  941. if (flag1 && _wall.start != startPointId && _wall.end != startPointId) {
  942. flag = this.isOKForCrossTwoWall3(position1, startPoint, key)
  943. }
  944. if (!flag) {
  945. return false
  946. }
  947. if (flag2 && _wall.start != endPointId && _wall.end != endPointId) {
  948. flag = this.isOKForCrossTwoWall3(position2, endPoint, key)
  949. }
  950. if (!flag) {
  951. return false
  952. }
  953. }
  954. return flag
  955. }
  956. // 更新pointId的坐标
  957. updatePointForMoveWall(wallId, pointId, virtualInfo, limitWallId, needNew) {
  958. const point = floorplanService.getPoint(pointId)
  959. const wall = floorplanService.getWall(wallId)
  960. // 如果没有约束墙,只有两种情况:一种是不新建墙,另一种是需要新建墙
  961. if (limitWallId == null) {
  962. // 不需要新建墙,这种情况一般是pointId的parent只有一个
  963. if (!needNew) {
  964. point.setPosition(virtualInfo.virtualPosition)
  965. }
  966. // 新建墙
  967. else {
  968. this.createWallForMoveWall(pointId, wallId, virtualInfo.virtualPosition)
  969. this.needUpdateRoom = true
  970. }
  971. } else {
  972. /*
  973. 不新建墙:
  974. 1. 更新坐标(一种是当pointId的parent是2个,另一种是三个,但是wallId对应的两堵墙接近180°)
  975. 2. 拆分墙
  976. 3. 吸附邻居墙的另一个端点
  977. 新建墙:
  978. */
  979. // 不新建墙
  980. if (!needNew) {
  981. if (!virtualInfo.adsorb) {
  982. // 只更新坐标
  983. if (Object.keys(point.parent).length == 2) {
  984. point.setPosition(virtualInfo.virtualPosition)
  985. } else {
  986. const info = wallService.wallIdForMinAngle(pointId, wallId)
  987. const angle = wallService.AngleForWall(info.min0.wallId, info.min1.wallId)
  988. // 只更新坐标
  989. if (Object.keys(point.parent).length == 3 && angle > (Constant.maxAngle / 180) * Math.PI) {
  990. point.setPosition(virtualInfo.virtualPosition)
  991. }
  992. // 拆分墙
  993. else {
  994. const dir = wallService.getDirction(pointId, wallId)
  995. // 先断开链接
  996. wallService.subtraWallFromIntersect(pointId, wallId)
  997. const newPointId = wall.getPointId(dir)
  998. const newPoint = floorplanService.getPoint(newPointId)
  999. // 更新新坐标
  1000. newPoint.setPosition(virtualInfo.virtualPosition)
  1001. // 拆分
  1002. wallService.splitWall(limitWallId, newPointId, dir)
  1003. this.needUpdateRoom = true
  1004. }
  1005. }
  1006. }
  1007. // 吸附邻居墙的另一个端点。
  1008. else {
  1009. wallService.moveTo(pointId, virtualInfo.adsorbPointId)
  1010. this.needUpdateRoom = true
  1011. }
  1012. }
  1013. // 新建墙
  1014. else {
  1015. this.createWallForMoveWall(pointId, wallId, virtualInfo.virtualPosition)
  1016. this.needUpdateRoom = true
  1017. }
  1018. }
  1019. }
  1020. //
  1021. createWallForMoveWall(pointId, wallId, newPosition) {
  1022. const wall = floorplanService.getWall(wallId)
  1023. const dir = wallService.getDirction(pointId, wallId)
  1024. // 第一步是断开连接
  1025. wallService.subtraWallFromIntersect(pointId, wallId)
  1026. // 第二步更新端点坐标
  1027. const newPointId = wall.getPointId(dir)
  1028. const newPoint = floorplanService.getPoint(newPointId)
  1029. newPoint.setPosition(newPosition)
  1030. // 第三步先新建墙
  1031. wallService.createWall(pointId, newPointId)
  1032. // 还缺少wall和newWall相交,这需要等另一头的point完成后最后处理
  1033. }
  1034. deleteWallForLinked(wallId) {
  1035. const wall = floorplanService.getWall(wallId)
  1036. wallService.subtraWallFromIntersect(wall.start, wallId)
  1037. wallService.subtraWallFromIntersect(wall.end, wallId)
  1038. floorplanService.deleteWall(wallId)
  1039. }
  1040. clear(){
  1041. this.needUpdateRoom = false
  1042. this.startMoving = false
  1043. this.moveFlag = false
  1044. this.adsorbPointWalls = {}
  1045. this.splitWallId = null
  1046. }
  1047. }
  1048. const moveWall = new MoveWall()
  1049. export { moveWall }