|
@@ -1,181 +0,0 @@
|
|
|
-import { stateService } from '../Service/StateService'
|
|
|
-import { symbolService } from '../Service/SymbolService'
|
|
|
-import { floorplanService } from '../Service/FloorplanService'
|
|
|
-import { wallService } from '../Service/WallService.js'
|
|
|
-import { mathUtil } from '../MathUtil.js'
|
|
|
-import { coordinate } from '../Coordinate'
|
|
|
-import Constant from '../Constant'
|
|
|
-import SelectState from '../enum/SelectState'
|
|
|
-
|
|
|
-export default class MoveSymbol {
|
|
|
- constructor() {
|
|
|
- this.symbol = null
|
|
|
- }
|
|
|
-
|
|
|
- //拖拽symbol
|
|
|
- moveFullSymbol(point, symbolId, nearestWallId) {
|
|
|
- const symbol = floorplanService.getSymbol(symbolId)
|
|
|
- const wall = floorplanService.getWall(nearestWallId)
|
|
|
- if (!wall) {
|
|
|
- return null
|
|
|
- }
|
|
|
- const wallLine = wallService.getLine(wall)
|
|
|
- const vSymbolLine = mathUtil.getVerticalLine(wallLine, point)
|
|
|
- let distance = symbol.len
|
|
|
- if (distance == null) {
|
|
|
- distance = mathUtil.getDistance(symbol.startPoint, symbol.endPoint)
|
|
|
- }
|
|
|
- /*
|
|
|
- const twoParallels = mathUtil.getParallelLineForDistance(vSymbolLine, distance / 2)
|
|
|
- let point1 = mathUtil.getIntersectionPoint(twoParallels.line1, wallLine)
|
|
|
- let point2 = mathUtil.getIntersectionPoint(twoParallels.line2, wallLine)
|
|
|
-
|
|
|
- //墙比较短
|
|
|
- if (mathUtil.getDistance(point1, point2) < Constant.minSymbolLen) {
|
|
|
- return null
|
|
|
- }
|
|
|
- //调整
|
|
|
- const startPoint = floorplanService.getPoint(wall.start)
|
|
|
- const endPoint = floorplanService.getPoint(wall.end)
|
|
|
- let dx, dy
|
|
|
-
|
|
|
- let _point1 = {}
|
|
|
- let _point2 = {}
|
|
|
- if (!wallService.isContain(wall, point1)) {
|
|
|
- dx = startPoint.x - point1.x
|
|
|
- dy = startPoint.y - point1.y
|
|
|
- _point2.x = point2.x + dx
|
|
|
- _point2.y = point2.y + dy
|
|
|
- if (!wallService.isContain(wall, _point2)) {
|
|
|
- dx = endPoint.x - point1.x
|
|
|
- dy = endPoint.y - point1.y
|
|
|
-
|
|
|
- point2.x += dx
|
|
|
- point2.y += dy
|
|
|
- mathUtil.clonePoint(point1, endPoint)
|
|
|
- } else {
|
|
|
- point2.x += dx
|
|
|
- point2.y += dy
|
|
|
- mathUtil.clonePoint(point1, startPoint)
|
|
|
- }
|
|
|
- } else if (!wallService.isContain(wall, point2)) {
|
|
|
- dx = startPoint.x - point2.x
|
|
|
- dy = startPoint.y - point2.y
|
|
|
- _point1.x = point1.x + dx
|
|
|
- _point1.y = point1.y + dy
|
|
|
- if (!wallService.isContain(wall, _point1)) {
|
|
|
- dx = endPoint.x - point2.x
|
|
|
- dy = endPoint.y - point2.y
|
|
|
-
|
|
|
- point1.x += dx
|
|
|
- point1.y += dy
|
|
|
- mathUtil.clonePoint(point2, endPoint)
|
|
|
- } else {
|
|
|
- point1.x += dx
|
|
|
- point1.y += dy
|
|
|
- mathUtil.clonePoint(point2, startPoint)
|
|
|
- }
|
|
|
- }
|
|
|
- const newPositions = symbolService.getNewForContainSymbols(point1, point2, nearestWallId, symbolId)
|
|
|
- */
|
|
|
- let _point = mathUtil.getIntersectionPoint(vSymbolLine, wallLine)
|
|
|
- const newPositions = symbolService.getNewPosForSymbol(_point, nearestWallId, symbolId)
|
|
|
- // // 和其他symbol相交
|
|
|
- // if (newPositions == null) {
|
|
|
- // return null
|
|
|
- // } else if (newPositions.collision) {
|
|
|
- // mathUtil.clonePoint(point1, newPositions.position1)
|
|
|
- // mathUtil.clonePoint(point2, newPositions.position2)
|
|
|
- // }
|
|
|
- if (newPositions != null && newPositions.state) {
|
|
|
- let dir = mathUtil.dotPoints(symbol.startPoint, symbol.endPoint, newPositions.position1, newPositions.position2)
|
|
|
- if (dir > 0) {
|
|
|
- mathUtil.clonePoint(symbol.startPoint, newPositions.position1)
|
|
|
- mathUtil.clonePoint(symbol.endPoint, newPositions.position2)
|
|
|
- } else {
|
|
|
- mathUtil.clonePoint(symbol.endPoint, newPositions.position1)
|
|
|
- mathUtil.clonePoint(symbol.startPoint, newPositions.position2)
|
|
|
- }
|
|
|
-
|
|
|
- //换墙
|
|
|
- if (symbol.parent != nearestWallId) {
|
|
|
- symbolService.changeSymbolForBelong(symbolId, nearestWallId)
|
|
|
- }
|
|
|
-
|
|
|
- symbol.setOpenSide(point)
|
|
|
- symbol.setPoints2d()
|
|
|
- }
|
|
|
-
|
|
|
- // if (mathUtil.getDistance(point1, symbol.startPoint) < mathUtil.getDistance(point1, symbol.endPoint)) {
|
|
|
- // symbol.setSymbolPosition(point1, 'start')
|
|
|
- // symbol.setSymbolPosition(point2, 'end')
|
|
|
- // } else {
|
|
|
- // symbol.setSymbolPosition(point2, 'start')
|
|
|
- // symbol.setSymbolPosition(point1, 'end')
|
|
|
- // }
|
|
|
- }
|
|
|
-
|
|
|
- // 拖拽symbol的端点
|
|
|
- moveSymbolPoint(targetPosition, symbolId, selectState) {
|
|
|
- const newInfo = symbolService.moveSymbolSinglePoint(targetPosition, symbolId, selectState)
|
|
|
- // symbol的start和end位置交换了
|
|
|
- if (newInfo == null) {
|
|
|
- return null
|
|
|
- }
|
|
|
- const symbol = floorplanService.getSymbol(symbolId)
|
|
|
- const midPoint = {
|
|
|
- x: (symbol.startPoint.x + symbol.endPoint.x) / 2,
|
|
|
- y: (symbol.startPoint.y + symbol.endPoint.y) / 2,
|
|
|
- }
|
|
|
- const distance = mathUtil.getDistance(midPoint, newInfo.position)
|
|
|
- // 太短了
|
|
|
- if (distance < Constant.minSymbolLen) {
|
|
|
- return null
|
|
|
- }
|
|
|
-
|
|
|
- const wall = floorplanService.getWall(symbol.parent)
|
|
|
- const startPoint = floorplanService.getPoint(wall.start)
|
|
|
- const endPoint = floorplanService.getPoint(wall.end)
|
|
|
-
|
|
|
- if (selectState == SelectState.Start) {
|
|
|
- // 与其他symbol重合
|
|
|
- const newPositions = symbolService.getNewForContainSymbols(symbol.endPoint, newInfo.position, symbol.parent, symbolId)
|
|
|
- if (newPositions == null || newPositions.collision) {
|
|
|
- return null
|
|
|
- }
|
|
|
-
|
|
|
- // 在wall内
|
|
|
- if (wallService.isContain(wall, newInfo.position)) {
|
|
|
- symbolService.setPosition(symbol, newInfo.position, 'start')
|
|
|
- }
|
|
|
- // 离wall的start近还是end近
|
|
|
- else {
|
|
|
- if (mathUtil.getDistance(symbol.startPoint, startPoint) < mathUtil.getDistance(symbol.startPoint, endPoint)) {
|
|
|
- symbolService.setPosition(symbol, startPoint, 'start')
|
|
|
- } else {
|
|
|
- symbolService.setPosition(symbol, endPoint, 'start')
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 与其他symbol重合
|
|
|
- const newPositions = symbolService.getNewForContainSymbols(symbol.startPoint, newInfo.position, symbol.parent, symbolId)
|
|
|
- if (newPositions == null || newPositions.collision) {
|
|
|
- return null
|
|
|
- }
|
|
|
-
|
|
|
- if (wallService.isContain(wall, newInfo.position)) {
|
|
|
- symbolService.setPosition(symbol, newInfo.position, 'end')
|
|
|
- } else {
|
|
|
- if (mathUtil.getDistance(symbol.endPoint, startPoint) < mathUtil.getDistance(symbol.endPoint, endPoint)) {
|
|
|
- symbolService.setPosition(symbol, startPoint, 'end')
|
|
|
- } else {
|
|
|
- symbolService.setPosition(symbol, endPoint, 'end')
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- symbol.setPoints2d()
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-const moveSymbol = new MoveSymbol()
|
|
|
-export { moveSymbol }
|