xushiting 3 лет назад
Родитель
Сommit
8ddcf28728

+ 13 - 0
src/views/draw-file/board/editCAD/Geometry/Circle.js

@@ -10,4 +10,17 @@ export default class Circle extends Geometry {
         this.geoType = VectorType.Circle
         this.setId(vectorId)
     }
+
+    isContain(position){
+        const dis = mathUtil.getDistance(position, this.position)
+        if(Math.abs(this.radius - dis)<Constant.minAdsorb){
+            return 'side'
+        }
+        else if((dis-this.radius)>Constant.minAdsorb){
+            return null;
+        }
+        else if((this.radius - dis)>Constant.minAdsorb){
+            return 'all'
+        }
+    }
 }

+ 33 - 0
src/views/draw-file/board/editCAD/Geometry/Rectangle.js

@@ -1,5 +1,7 @@
 import VectorType from '../enum/VectorType.js'
 import Geometry from './Geometry.js'
+import Constant from '../Constant.js'
+import { mathUtil } from '../MathUtil.js'
 
 export default class Rectangle extends Geometry {
     constructor(position, vectorId, floor) {
@@ -10,4 +12,35 @@ export default class Rectangle extends Geometry {
         this.geoType = VectorType.Rectangle
         this.setId(vectorId)
     }
+
+    isContain(position){
+        for(let i=0;i<this.points.length;++i){
+            const dis = mathUtil.getDistance(position, this.points[i])
+            if(dis < Constant.minAdsorb){
+                return {
+                    vertex:i
+                };
+            }
+        }
+
+        for(let i=0;i<this.points.length;++i){
+            let point1 = this.points[i];
+            let point2 = this.points[i+1];
+            if(i == this.points.length-1){
+                point2 = this.points[0]
+            }
+            let flag = mathUtil.isContainForSegment(position, point1, point2)
+            if (flag) {
+                return {
+                    side:i
+                };
+            }
+        }
+
+        let flag = mathUtil.isPointInPoly(position, this.points)
+        if(flag){
+            return 'all'
+        }
+        return null;
+    }
 }

+ 94 - 31
src/views/draw-file/board/editCAD/ListenLayer.js

@@ -18,13 +18,33 @@ export default class ListenLayer {
             state: null,
         }
 
-        this.componentInfo = {
-            componentId: null,
+        this.tagInfo = {
+            tagId: null,
             state: null,
         }
 
-        this.tagInfo = {
-            tagId: null,
+        this.tableInfo = {
+            tableId: null,
+            state: null,
+        }
+
+        this.rectangleInfo = {
+            rectangleId: null,
+            state: null,
+        }
+
+        this.circleInfo = {
+            circleId: null,
+            state: null,
+        }
+
+        this.arrowInfo = {
+            arrowId: null,
+            state: null,
+        }
+
+        this.iconInfo = {
+            iconId: null,
             state: null,
         }
 
@@ -39,20 +59,6 @@ export default class ListenLayer {
     //开始监听,exceptPointId表示不考虑的点,exceptWallIds表示不考虑的墙
     start(position, exceptPointId, exceptWallIds) {
         let nearest = this.getNearForVectors(position, exceptPointId, exceptWallIds)
-        /*
-        // getNearForWalls在一定的条件下必须执行两次!
-        // 如果吸附在墙面上,或者吸附在其余墙的顶点(x/y坐标),这时候因为抖动,可能会变成完全吸附在墙角,这时候是要再执行一次getNearForWalls
-        if (
-            nearest.modifyPoint &&
-            (nearest.modifyPoint.hasOwnProperty("linkedPointIdX") || 
-            nearest.modifyPoint.hasOwnProperty("linkedPointIdY") || 
-            nearest.modifyPoint.hasOwnProperty("linkedWallId"))
-        ) {
-            mathUtil.clonePoint(position, nearest.modifyPoint);
-            nearest = this.getNearForVectors(position, exceptPointId, exceptWallIds);
-        }
-        */
-
         if (
             nearest.modifyPoint &&
             (nearest.modifyPoint.hasOwnProperty('linkedPointId') ||
@@ -234,10 +240,15 @@ export default class ListenLayer {
                 _modifyPoint.linkedWallId = wallId
             }
         }
+
         const result = {
             minPoint: min1,
             minWall: min2,
-            componentInfo: {},
+            tableInfo: {},
+            rectangleInfo: {},
+            circleInfo: {},
+            arrowInfo: {},
+            iconInfo: {},
             tagInfo: {},
             signInfo: {},
         }
@@ -256,26 +267,78 @@ export default class ListenLayer {
             result.modifyPoint.y = modifyPoint.y
         }
 
-        const components = floorplanService.getComponents()
-        for (const componentId in components) {
-            const component = floorplanService.getComponent(componentId)
-            const location = component.isContain(position)
+        const tags = floorplanService.getTags()
+        for (const tagId in tags) {
+            const tag = floorplanService.getTag(tagId)
+            const location = tag.isContain(position)
+            if (location) {
+                result.tagInfo = {
+                    tagId: tagId,
+                    state: 'all',
+                }
+                break
+            }
+        }
+
+        // const tables = floorplanService.getTables()
+        // for (const tableId in tables) {
+        //     const table = floorplanService.getTable(tableId)
+        //     const location = table.isContain(position)
+        //     if (location) {
+        //         result.tableInfo = {
+        //             tableId: tableId,
+        //             state: 'all',
+        //         }
+        //         break
+        //     }
+        // }
+
+        const rectangles = floorplanService.getRectangles()
+        for (const rectangleId in rectangles) {
+            const rectangle = floorplanService.getRectangle(rectangleId)
+            const location = rectangle.isContain(position)
             if (location) {
-                result.componentInfo = {
-                    componentId: componentId,
+                result.rectangleInfo = {
+                    rectangleId: rectangleId,
                     state: 'all',
                 }
                 break
             }
         }
 
-        const tags = floorplanService.getTags()
-        for (const tagId in tags) {
-            const tag = floorplanService.getTag(tagId)
-            const location = tag.isContain(position)
+        const circles = floorplanService.getCircles()
+        for (const circleId in circles) {
+            const circle = floorplanService.getRectangle(circleId)
+            const location = circle.isContain(position)
             if (location) {
-                result.tagInfo = {
-                    tagId: tagId,
+                result.circleInfo = {
+                    circleId: circleId,
+                    state: 'all',
+                }
+                break
+            }
+        }
+
+        const arrows = floorplanService.getArrows()
+        for (const arrowId in arrows) {
+            const arrow = floorplanService.getRectangle(arrowId)
+            const location = arrow.isContain(position)
+            if (location) {
+                result.arrowInfo = {
+                    arrowId: arrowId,
+                    state: 'all',
+                }
+                break
+            }
+        }
+
+        const icons = floorplanService.getIcons()
+        for (const iconId in icons) {
+            const icon = floorplanService.getRectangle(iconId)
+            const location = icon.isContain(position)
+            if (location) {
+                result.iconInfo = {
+                    iconId: iconId,
                     state: 'all',
                 }
                 break